Skip to content

Commit 9727fdc

Browse files
committed
fix: expand and fix error messages in BMA loading code
1 parent 1e29ef0 commit 9727fdc

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

ext/JSONExt.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ function entity_name_from_in_neighbors(entity, in_neighbors)
3434

3535
if length(entity_name) != 1
3636
error(
37-
"Error while constructing name for entity: $entity, with in neighbors: $in_neighbors",
37+
"""
38+
Error while constructing name for entity: $entity, with in neighbors: \
39+
$in_neighbors. There are more than one incoming neighbor entities with the same \
40+
name. To fix this error, remove the erroneous relationships from the JSON file, \
41+
or reference the entity by id (like `var(3)`).
42+
""",
3843
)
3944
end
4045
return only(entity_name)
@@ -90,7 +95,6 @@ function to_from_variable_id(r, from_to)
9095
elseif haskey(r, k_w_id)
9196
return r[k_w_id]
9297
else
93-
@show keys(r)
9498
error("""
9599
Neither alternative key was found to retrieve the edge variable id. The \
96100
model file is not using the expected structure for BMA models.
@@ -110,17 +114,19 @@ function QualitativeNetwork(bma_file_path::AbstractString)
110114
names = [Symbol("$(v["name"])_$(v["id"])") for v in variables]
111115
mg = MetaGraph(SimpleDiGraph(), Int, Union{Expr,Integer,Symbol}, String)
112116

113-
foreach(id_to_name) do (id, n)
117+
foreach(variables) do v
118+
id = v["id"]
119+
name = v["name"]
114120
# adding an empty expression: :()
115121
# because we need to construct the interaction graph
116122
# first before parsing the functions correctly
117123
added = add_vertex!(mg, id, :())
118124
if !added
119125
error(
120126
"""
121-
Failed to add the entity ($n, id: $id) from the input file while \
127+
Failed to add the entity (\"$name\", id: #$id) from the input file while \
122128
constructing the QN. Check that there is only one entity in the model with \
123-
the id $id.
129+
the id #$id.
124130
""",
125131
)
126132
end

0 commit comments

Comments
 (0)