Skip to content

Commit 25c3054

Browse files
authored
Merge pull request #71 from JuliaRobotics/enhancement/messageonserializationerror
try/catches around serialization
2 parents b01d21a + 51ddcc3 commit 25c3054

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/FileDFG/services/FileDFG.jl

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,17 @@ function _packFactor(dfg::G, f::DFGFactor)::Dict{String, Any} where G <: Abstrac
4343
props["tags"] = JSON2.write(f.tags)
4444
# Pack the node data
4545
fnctype = f.data.fnc.usrfnc!
46-
packtype = getfield(_getmodule(fnctype), Symbol("Packed$(_getname(fnctype))"))
47-
packed = convert(PackedFunctionNodeData{packtype}, f.data)
48-
props["data"] = JSON2.write(packed)
46+
try
47+
packtype = getfield(_getmodule(fnctype), Symbol("Packed$(_getname(fnctype))"))
48+
packed = convert(PackedFunctionNodeData{packtype}, f.data)
49+
props["data"] = JSON2.write(packed)
50+
catch ex
51+
io = IOBuffer()
52+
showerror(io, ex, catch_backtrace())
53+
err = String(take!(io))
54+
msg = "Error while packing '$(f.label)' as '$fnctype', please check the unpacking/packing converters for this factor - \r\n$err"
55+
error(msg)
56+
end
4957
# Include the type
5058
props["fnctype"] = String(_getname(fnctype))
5159
props["_variableOrderSymbols"] = JSON2.write(f._variableOrderSymbols)
@@ -61,11 +69,21 @@ function _unpackFactor(dfg::G, packedProps::Dict{String, Any}, iifModule)::DFGFa
6169
tags = JSON2.read(packedProps["tags"], Vector{Symbol})
6270

6371
data = packedProps["data"]
72+
@debug "Decoding $label..."
6473
datatype = packedProps["fnctype"]
6574
packtype = getfield(Main, Symbol("Packed"*datatype))
66-
packed = JSON2.read(data, GenericFunctionNodeData{packtype,String})
67-
fullFactor = iifModule.decodePackedType(dfg, packed)
68-
# fullFactor = dfg.decodePackedTypeFunc(dfg, packed)
75+
packed = nothing
76+
fullFactor = nothing
77+
try
78+
packed = JSON2.read(data, GenericFunctionNodeData{packtype,String})
79+
fullFactor = iifModule.decodePackedType(dfg, packed)
80+
catch ex
81+
io = IOBuffer()
82+
showerror(io, ex, catch_backtrace())
83+
err = String(take!(io))
84+
msg = "Error while unpacking '$label' as '$datatype', please check the unpacking/packing converters for this factor - \r\n$err"
85+
error(msg)
86+
end
6987

7088
# Include the type
7189
_variableOrderSymbols = JSON2.read(packedProps["_variableOrderSymbols"], Vector{Symbol})

0 commit comments

Comments
 (0)