Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message when given bad path #113

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/serialization/ExcelACSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ installed and imported.
to Excel table specifications
"""
function read_xlsx_acset(cons, source::Union{AbstractString,IO}; kw...)
if typeof(source) <: AbstractString
ispath(source) || error("$(source) is not a valid path to a file")
end
read_acset(cons, read_xlsx(source); kw...)
end

Expand Down
2 changes: 2 additions & 0 deletions src/serialization/JSONACSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ end
Inverse to [`write_json_acset`](@ref).
"""
function read_json_acset(ty, fname::AbstractString)
ispath(fname) || error("$(fname) is not a valid path to a file")
parse_json_acset(ty, JSON3.read(fname))
end

Expand Down Expand Up @@ -164,6 +165,7 @@ Similar to [`parse_json_acset_schema`](@ref) except reads from a file.
Inverse to [`write_json_acset_schema`](@ref).
"""
function read_json_acset_schema(T, fname::AbstractString)
ispath(fname) || error("$(fname) is not a valid path to a file")
parse_json_acset_schema(T, JSON3.read(fname))
end

Expand Down
5 changes: 5 additions & 0 deletions test/serialization/ExcelACSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,9 @@ result = read_xlsx_acset(LabeledGraph{String}, labeled_graph_path, tables=(
))
@test result == g

# General functionality
# ---------------------

@test_throws Exception read_xlsx_acset(LabeledGraph{String}, "badpath.json")

end
4 changes: 4 additions & 0 deletions test/serialization/JSONACSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ add_parts!(ldds, :X, 4, Φ=[2,3,4,1], label=[AttrVar(1), :a, :b, AttrVar(2)])
json = generate_json_acset(ldds)
@test all(row -> haskey(row, :_id), json[:Label])

@test_throws Exception read_json_acset(Graph, "badfile.json")

# Schema serialization
######################

Expand All @@ -71,4 +73,6 @@ for schema in [SchGraph, SchWeightedGraph, SchLabeledDDS]
@test roundtrip_json_acset_schema(schema) == schema
end

@test_throws Exception read_json_acset_schema(BasicSchema, "badfile.json")

end
Loading