diff --git a/NEWS.md b/NEWS.md index aad56560..20b51c3c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -22,6 +22,7 @@ Listing news on any major breaking changes in DFG. For regular changes, see int - Deprecate getBlobentryFirst -> getfirstBlobentry, see #1114 - OrderedDict is no longer exported - FolderStore path now includes the store label. +- Standardized error types and behaviour. # v0.26 - Graph structure plotting now uses GraphMakie.jl instead of GraphPlot.jl. Update by replacing `using GraphPlot` with `using GraphMakie`. diff --git a/docs/src/func_ref.md b/docs/src/func_ref.md index b6ba5df8..632c7dc9 100644 --- a/docs/src/func_ref.md +++ b/docs/src/func_ref.md @@ -44,6 +44,12 @@ Modules = [DistributedFactorGraphs] Pages = ["entities/DFGFactor.jl"] ``` +### Error Types +```@autodocs +Modules = [DistributedFactorGraphs] +Pages = ["errors.jl"] +``` + ## DFG Plots [GraphMakie.jl] ```@autodocs diff --git a/src/DataBlobs/services/BlobEntry.jl b/src/DataBlobs/services/BlobEntry.jl index 76e7d582..28f717e2 100644 --- a/src/DataBlobs/services/BlobEntry.jl +++ b/src/DataBlobs/services/BlobEntry.jl @@ -67,18 +67,14 @@ Also see: [`addBlobentry!`](@ref), [`getBlob`](@ref), [`listBlobentries`](@ref) """ function getBlobentry(var::AbstractDFGVariable, key::Symbol) if !hasBlobentry(var, key) - throw( - KeyError( - "No dataEntry label $(key) found in variable $(getLabel(var)). Available keys: $(keys(var.dataDict))", - ), - ) + throw(LabelNotFoundError("Blobentry", key, collect(keys(var.dataDict)))) end return var.dataDict[key] end function getBlobentry(var::VariableDFG, key::Symbol) if !hasBlobentry(var, key) - throw(KeyError(key)) + throw(LabelNotFoundError("Blobentry", key)) end return var.blobEntries[findfirst(x -> x.label == key, var.blobEntries)] end @@ -156,19 +152,18 @@ Should be extended if DFG variable is not returned by reference. Also see: [`getBlobentry`](@ref), [`addBlob!`](@ref), [`mergeBlobentries!`](@ref) """ -function addBlobentry!(var::AbstractDFGVariable, entry::Blobentry;) +function addBlobentry!(var::AbstractDFGVariable, entry::Blobentry) # see https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/985 # blobId::Union{UUID,Nothing} = (isnothing(entry.blobId) ? entry.id : entry.blobId), # blobSize::Int = (hasfield(Blobentry, :size) ? entry.size : -1) - haskey(var.dataDict, entry.label) && - error("blobEntry $(entry.label) already exists on variable $(getLabel(var))") + haskey(var.dataDict, entry.label) && throw(LabelExistsError("Blobentry", entry.label)) var.dataDict[entry.label] = entry return entry end function addBlobentry!(var::VariableDFG, entry::Blobentry) entry.label in getproperty.(var.blobEntries, :label) && - error("blobEntry $(entry.label) already exists on variable $(getLabel(var))") + throw(LabelExistsError("Blobentry", entry.label)) push!(var.blobEntries, entry) return entry end diff --git a/src/Deprecated.jl b/src/Deprecated.jl index 1d971e81..9a84c586 100644 --- a/src/Deprecated.jl +++ b/src/Deprecated.jl @@ -420,6 +420,16 @@ function fncStringToData(args...; kwargs...) return error("fncStringToData is obsolete.") end +#TODO make sure getFactorOperationalMemoryType is obsolete +function getFactorOperationalMemoryType(dummy) + return error( + "Please extend your workspace with function getFactorOperationalMemoryType(<:AbstractParams) for your usecase, e.g. IncrementalInference uses `CommonConvWrapper <: FactorSolverCache`", + ) +end +function getFactorOperationalMemoryType(dfg::AbstractDFG) + return getFactorOperationalMemoryType(getSolverParams(dfg)) +end + ## ================================================================================ ## Deprecated in v0.25 ##================================================================================= diff --git a/src/DistributedFactorGraphs.jl b/src/DistributedFactorGraphs.jl index 7eb6c7bb..f90a1a73 100644 --- a/src/DistributedFactorGraphs.jl +++ b/src/DistributedFactorGraphs.jl @@ -354,6 +354,7 @@ export plotDFG ##============================================================================== # Entities +include("errors.jl") include("entities/AbstractDFG.jl") diff --git a/src/GraphsDFG/FactorGraphs/FactorGraphs.jl b/src/GraphsDFG/FactorGraphs/FactorGraphs.jl index 6b2d8877..28dc4641 100644 --- a/src/GraphsDFG/FactorGraphs/FactorGraphs.jl +++ b/src/GraphsDFG/FactorGraphs/FactorGraphs.jl @@ -139,9 +139,10 @@ function addFactor!( (@error "Label $(factor.label) already in fg"; return false) for vlabel in variableLabels - !haskey(g.labels, vlabel) && (throw(KeyError(vlabel)) - # @error "Variable '$(vlabel)' not found in graph when creating Factor '$(factor.label)'"; return false - ) #TODO debug error or exception? + if !haskey(g.labels, vlabel) + @error "Variable '$(vlabel)' not found in graph when creating Factor '$(factor.label)'" + return false + end end add_vertex!(g.graph) || return false diff --git a/src/GraphsDFG/GraphsDFG.jl b/src/GraphsDFG/GraphsDFG.jl index f97d86ec..222930f3 100644 --- a/src/GraphsDFG/GraphsDFG.jl +++ b/src/GraphsDFG/GraphsDFG.jl @@ -8,7 +8,7 @@ using OrderedCollections using StructTypes using ...DistributedFactorGraphs -using ...DistributedFactorGraphs: Agent +using ...DistributedFactorGraphs: Agent, LabelNotFoundError, LabelExistsError # import DFG functions to extend import ...DistributedFactorGraphs: diff --git a/src/GraphsDFG/services/GraphsDFG.jl b/src/GraphsDFG/services/GraphsDFG.jl index 3200eb05..b3a635c6 100644 --- a/src/GraphsDFG/services/GraphsDFG.jl +++ b/src/GraphsDFG/services/GraphsDFG.jl @@ -42,9 +42,8 @@ function addVariable!( dfg::GraphsDFG{<:AbstractParams, V, <:AbstractDFGFactor}, variable::V, ) where {V <: AbstractDFGVariable} - #TODO should this be an error if haskey(dfg.g.variables, variable.label) - error("Variable '$(variable.label)' already exists in the factor graph") + throw(LabelExistsError("Variable", variable.label)) end FactorGraphs.addVariable!(dfg.g, variable) || return false @@ -104,11 +103,15 @@ function addFactor!( factor::F, ) where {F <: AbstractDFGFactor} if haskey(dfg.g.factors, factor.label) - error("Factor '$(factor.label)' already exists in the factor graph") + throw(LabelExistsError("Factor", factor.label)) end # TODO # @assert FactorGraphs.addFactor!(dfg.g, getVariableOrder(factor), factor) - @assert FactorGraphs.addFactor!(dfg.g, Symbol[factor._variableOrderSymbols...], factor) + variableLabels = Symbol[factor._variableOrderSymbols...] + for vlabel in variableLabels + !exists(dfg, vlabel) && throw(LabelNotFoundError("Variable", vlabel)) + end + @assert FactorGraphs.addFactor!(dfg.g, variableLabels, factor) return factor end @@ -121,7 +124,7 @@ end function getVariable(dfg::GraphsDFG, label::Symbol) if !haskey(dfg.g.variables, label) - error("Variable label '$(label)' does not exist in the factor graph") + throw(LabelNotFoundError("Variable", label)) end return dfg.g.variables[label] @@ -129,8 +132,7 @@ end function getFactor(dfg::GraphsDFG, label::Symbol) if !haskey(dfg.g.factors, label) - #TODO throw a typed error - error("Factor label '$(label)' does not exist in the factor graph") + throw(LabelNotFoundError("Factor", label)) end return dfg.g.factors[label] end @@ -151,8 +153,8 @@ function mergeFactor!(dfg::GraphsDFG, factor::AbstractDFGFactor;) #TODO should we allow merging the factor neighbors or error as before? error("Cannot update the factor, the neighbors are not the same.") # We need to delete the factor if we are updating the neighbors - deleteFactor!(dfg, factor.label) - addFactor!(dfg, factor) + # deleteFactor!(dfg, factor.label) + # addFactor!(dfg, factor) else dfg.g.factors[factor.label] = factor end @@ -162,7 +164,7 @@ end function deleteVariable!(dfg::GraphsDFG, label::Symbol)#::Tuple{AbstractDFGVariable, Vector{<:AbstractDFGFactor}} if !haskey(dfg.g.variables, label) - error("Variable label '$(label)' does not exist in the factor graph") + throw(LabelNotFoundError("Variable", label)) end deleteNeighbors = true # reserved, orphaned factors are not supported at this time @@ -175,7 +177,7 @@ end function deleteFactor!(dfg::GraphsDFG, label::Symbol; suppressGetFactor::Bool = false) if !haskey(dfg.g.factors, label) - error("Factor label '$(label)' does not exist in the factor graph") + throw(LabelNotFoundError("Factor", label)) end rem_vertex!(dfg.g, dfg.g.labels[label]) return 1 @@ -280,10 +282,7 @@ end function _isSolvable(dfg::GraphsDFG, label::Symbol, ready::Int) haskey(dfg.g.variables, label) && (return dfg.g.variables[label].solvable >= ready) haskey(dfg.g.factors, label) && (return dfg.g.factors[label].solvable >= ready) - - #TODO should this be a breaking error? - @error "Node not in factor or variable" - return false + throw(LabelNotFoundError(label)) end function listNeighbors(dfg::GraphsDFG, node::DFGNode; solvable::Int = 0) @@ -292,7 +291,7 @@ end function listNeighbors(dfg::GraphsDFG, label::Symbol; solvable::Int = 0) if !exists(dfg, label) - error("Variable/factor with label '$(label)' does not exist in the factor graph") + throw(LabelNotFoundError(label)) end neighbors_il = FactorGraphs.outneighbors(dfg.g, dfg.g.labels[label]) @@ -540,9 +539,7 @@ end function addGraphBlobentry!(fg::GraphsDFG, entry::Blobentry) if haskey(fg.graphBlobEntries, entry.label) - error( - "Blobentry '$(entry.label)' already exists in the factor graph's blob entries.", - ) + throw(LabelExistsError("Blobentry", entry.label)) end push!(fg.graphBlobEntries, entry.label => entry) return entry diff --git a/src/errors.jl b/src/errors.jl new file mode 100644 index 00000000..4b1d7fe0 --- /dev/null +++ b/src/errors.jl @@ -0,0 +1,57 @@ +""" + LabelNotFoundError(label, available) + +Error thrown when a requested label is not found in the factor graph. +""" +struct LabelNotFoundError <: Exception + name::String + label::Symbol + available::Vector{Symbol} +end + +LabelNotFoundError(name::String, label::Symbol) = LabelNotFoundError(name, label, Symbol[]) +LabelNotFoundError(label::Symbol) = LabelNotFoundError("Node", label, Symbol[]) + +function Base.showerror(io::IO, ex::LabelNotFoundError) + print(io, "LabelNotFoundError: ", ex.name, " label '", ex.label, "' not found.") + if !isempty(ex.available) + println(io, " Available labels:") + show(io, ex.available) + end +end + +""" + LabelExistsError(label) + +Error thrown when attempting to add a label that already exists in the collection. +""" +struct LabelExistsError <: Exception + name::String + label::Symbol +end + +LabelExistsError(label::Symbol) = LabelExistsError("Node", label) + +function Base.showerror(io::IO, ex::LabelExistsError) + return print( + io, + "LabelExistsError: ", + ex.name, + " label '", + ex.label, + "' already exists.", + ) +end + +""" + SerializationError(msg) + +Error thrown when serialization or deserialization fails. +""" +struct SerializationError <: Exception + msg::String +end + +function Base.showerror(io::IO, ex::SerializationError) + return print(io, "SerializationError: ", ex.msg) +end diff --git a/src/services/AbstractDFG.jl b/src/services/AbstractDFG.jl index 27cafa66..8f716bc7 100644 --- a/src/services/AbstractDFG.jl +++ b/src/services/AbstractDFG.jl @@ -97,20 +97,6 @@ getAddHistory(dfg::AbstractDFG) = dfg.addHistory """ getSolverParams(dfg::AbstractDFG) = dfg.solverParams -""" - $(SIGNATURES) - -Method must be overloaded by the user for Serialization to work. E.g. IncrementalInference uses `CommonConvWrapper <: FactorSolverCache`. -""" -function getFactorOperationalMemoryType(dummy) - return error( - "Please extend your workspace with function getFactorOperationalMemoryType(<:AbstractParams) for your usecase, e.g. IncrementalInference uses `CommonConvWrapper <: FactorSolverCache`", - ) -end -function getFactorOperationalMemoryType(dfg::AbstractDFG) - return getFactorOperationalMemoryType(getSolverParams(dfg)) -end - """ $(SIGNATURES) @@ -121,7 +107,10 @@ function rebuildFactorCache!( factor::AbstractDFGFactor, neighbors = [], ) - @warn("rebuildFactorCache! is not implemented for $(typeof(dfg))") + @warn( + "FactorCache not build, rebuildFactorCache! is not implemented for $(typeof(dfg)). Make sure to load IncrementalInference.", + maxlog = 1 + ) return nothing end @@ -533,7 +522,7 @@ function getVariable(dfg::AbstractDFG, label::Symbol, solveKey::Symbol) var = getVariable(dfg, label) if isa(var, VariableCompute) && !haskey(var.solverDataDict, solveKey) - error("Solvekey '$solveKey' does not exists in the variable") + throw(LabelNotFoundError("VariableNode", solveKey)) elseif !isa(var, VariableCompute) @warn "getVariable(dfg, label, solveKey) only supported for type VariableCompute." end @@ -1096,7 +1085,7 @@ function copyGraph!( elseif overwriteDest mergeVariable!(destDFG, variableCopy) else - error("Variable $(variable.label) already exists in destination graph!") + throw(LabelExistsError("Variable", variable.label)) end end # And then all factors to the destDFG. diff --git a/src/services/DFGVariable.jl b/src/services/DFGVariable.jl index 984c1925..7a1fe9f5 100644 --- a/src/services/DFGVariable.jl +++ b/src/services/DFGVariable.jl @@ -276,14 +276,7 @@ Notes: - used by both factor graph variable and Bayes tree clique logic. """ function isInitialized(var::VariableCompute, key::Symbol = :default) - data = getVariableState(var, key) - if data === nothing - #TODO we still have a mixture of 2 error behaviours - # DF, not sure I follow the error here? - return false - else - return data.initialized - end + return getVariableState(var, key).initialized end function isInitialized(dfg::AbstractDFG, label::Symbol, key::Symbol = :default) @@ -453,7 +446,11 @@ Related getMeanPPE, getMaxPPE, getKDEMean, getKDEFit, getPPEs, getVariablePPEs """ function getPPE(vari::VariableDataLevel1, solveKey::Symbol = :default) - return getPPEDict(vari)[solveKey] + if haskey(getPPEDict(vari), solveKey) + return getPPEDict(vari)[solveKey] + else + throw(LabelNotFoundError("PPE", solveKey, collect(keys(getPPEDict(vari))))) + end # return haskey(ppeDict, solveKey) ? ppeDict[solveKey] : nothing end @@ -501,9 +498,9 @@ Retrieve solver data structure stored in a variable. function getVariableState(v::VariableCompute, key::Symbol = :default) #TODO this does not fit in with some of the other error behaviour. but its used so added @error vnd = if haskey(getSolverDataDict(v), key) - getSolverDataDict(v)[key] + return getSolverDataDict(v)[key] else - (@error "Variable $(getLabel(v)) does not have solver data $(key)"; nothing) + throw(LabelNotFoundError("State", key)) end return vnd end @@ -539,7 +536,7 @@ Add a Metadata pair `key=>value` for variable `label` in `dfg` """ function addMetadata!(dfg::AbstractDFG, label::Symbol, pair::Pair{Symbol, <:SmallDataTypes}) v = getVariable(dfg, label) - haskey(v.smallData, pair.first) && error("$(pair.first) already exists.") + haskey(v.smallData, pair.first) && throw(LabelExistsError("Metadata", pair.first)) push!(v.smallData, pair) mergeVariable!(dfg, v) return v.smallData #or pair TODO @@ -648,8 +645,7 @@ function getVariableState( solvekey::Symbol = :default, ) v = getVariable(dfg, variablekey) - !haskey(v.solverDataDict, solvekey) && - throw(KeyError("Solve key '$solvekey' not found in variable '$variablekey'")) + !haskey(v.solverDataDict, solvekey) && throw(LabelNotFoundError("State", solvekey)) return v.solverDataDict[solvekey] end @@ -665,7 +661,7 @@ Add variable solver data, errors if it already exists. function addVariableState!(dfg::AbstractDFG, variablekey::Symbol, vnd::VariableState) var = getVariable(dfg, variablekey) if haskey(var.solverDataDict, vnd.solveKey) - error("VariableState '$(vnd.solveKey)' already exists") + throw(LabelExistsError("VariableState", vnd.solveKey)) end var.solverDataDict[vnd.solveKey] = vnd return vnd @@ -840,8 +836,7 @@ Related [`getPPEMean`](@ref), [`getPPEMax`](@ref), [`updatePPE!`](@ref), `mean(BeliefType)` """ function getPPE(v::VariableCompute, ppekey::Symbol = :default) - !haskey(v.ppeDict, ppekey) && - throw(KeyError("PPE key '$ppekey' not found in variable '$(getLabel(v))'")) + !haskey(v.ppeDict, ppekey) && throw(LabelNotFoundError("PPE", ppekey)) return v.ppeDict[ppekey] end function getPPE(dfg::AbstractDFG, variablekey::Symbol, ppekey::Symbol = :default) @@ -867,7 +862,7 @@ function addPPE!( ) where {P <: AbstractPointParametricEst} var = getVariable(dfg, variablekey) if haskey(var.ppeDict, ppe.solveKey) - error("PPE '$(ppe.solveKey)' already exists") + throw(LabelExistsError("PPE", ppe.solveKey)) end var.ppeDict[ppe.solveKey] = ppe return ppe @@ -964,7 +959,7 @@ function deletePPE!(dfg::AbstractDFG, variablekey::Symbol, ppekey::Symbol = :def var = getVariable(dfg, variablekey) if !haskey(var.ppeDict, ppekey) - throw(KeyError("VariableState '$(ppekey)' does not exist")) + throw(LabelNotFoundError("PPE", ppekey)) end pop!(var.ppeDict, ppekey) return 1 diff --git a/test/FactorGraphsTests.jl b/test/FactorGraphsTests.jl index 473d59fc..c11561e9 100644 --- a/test/FactorGraphsTests.jl +++ b/test/FactorGraphsTests.jl @@ -64,11 +64,11 @@ end [:a, :b], FactorSkeleton(:abf1, [:a, :b]), ) - @test_throws KeyError FactorGraphs.addFactor!( + @test @test_logs (:error, r"not found") FactorGraphs.addFactor!( fg, [:a, :c], FactorSkeleton(:acf1, [:a, :c]), - ) + ) == false @test eltype(fg) == Int diff --git a/test/GraphsDFGSummaryTypes.jl b/test/GraphsDFGSummaryTypes.jl index 766ce52e..dcb80cc7 100644 --- a/test/GraphsDFGSummaryTypes.jl +++ b/test/GraphsDFGSummaryTypes.jl @@ -114,7 +114,7 @@ end if VARTYPE == VariableSummary @test getTimestamp(v1) == v1.timestamp @test getVariablePPEDict(v1) == v1.ppeDict - @test_throws KeyError getVariablePPE(v1, :notfound) + @test_throws LabelNotFoundError getVariablePPE(v1, :notfound) @test getVariableTypeName(v1) == :Pose2 # FACTYPE == FactorSummary diff --git a/test/iifInterfaceTests.jl b/test/iifInterfaceTests.jl index 9f03ac1d..deca20db 100644 --- a/test/iifInterfaceTests.jl +++ b/test/iifInterfaceTests.jl @@ -72,19 +72,19 @@ end @test addVariable!(dfg2, v1) == v1 @test addVariable!(dfg2, v2) == v2 @test mergeVariable!(dfg2, v3) == 1 - @test_throws ErrorException addVariable!(dfg2, v3) + @test_throws LabelExistsError addVariable!(dfg2, v3) @test addFactor!(dfg2, f1) == f1 - @test_throws ErrorException addFactor!(dfg2, f1) + @test_throws LabelExistsError addFactor!(dfg2, f1) # @test @test_logs (:warn, r"exist") mergeFactor!(dfg2, f2) == f2 @test mergeFactor!(dfg2, f2) == 1 - @test_throws ErrorException addFactor!(dfg2, f2) + @test_throws LabelExistsError addFactor!(dfg2, f2) dv3 = deleteVariable!(dfg2, v3) @test dv3 == 2 - @test_throws ErrorException deleteVariable!(dfg2, v3) + @test_throws LabelNotFoundError deleteVariable!(dfg2, v3) @test issetequal(ls(dfg2), [:a, :b]) - @test_throws ErrorException deleteFactor!(dfg2, f2) + @test_throws LabelNotFoundError deleteFactor!(dfg2, f2) @test lsf(dfg2) == [:abf1] end @@ -170,10 +170,10 @@ end global dfg, v1, v2, f1 @test getVariable(dfg, v1.label) == v1 @test getFactor(dfg, f1.label) == f1 - @test_throws Exception getVariable(dfg, :nope) - @test_throws Exception getVariable(dfg, "nope") - @test_throws Exception getFactor(dfg, :nope) - @test_throws Exception getFactor(dfg, "nope") + @test_throws LabelNotFoundError getVariable(dfg, :nope) + @test_throws MethodError getVariable(dfg, "nope") + @test_throws LabelNotFoundError getFactor(dfg, :nope) + @test_throws MethodError getFactor(dfg, "nope") # Sets v1Prime = deepcopy(v1) @@ -186,7 +186,7 @@ end @test getTags(v1) == v1.tags @test getTimestamp(v1) == v1.timestamp @test getVariablePPEDict(v1) == v1.ppeDict - @test_throws Exception DistributedFactorGraphs.getVariablePPE(v1, :notfound) + @test_throws LabelNotFoundError DistributedFactorGraphs.getVariablePPE(v1, :notfound) @test getVariableState(v1) === v1.solverDataDict[:default] @test getVariableState(v1) === v1.solverDataDict[:default] @test getVariableState(v1, :default) === v1.solverDataDict[:default] @@ -210,7 +210,7 @@ end @test !isInitialized(dfg, :a) @test !isInitialized(v2) - @test !isInitialized(v2, :second) + @test_throws LabelNotFoundError isInitialized(v2, :second) # Session, robot, and user small data tests smallRobotData = Dict{Symbol, SmallDataTypes}(:a => "43", :b => "Hello") @@ -256,14 +256,14 @@ end v1 = getVariable(dfg, :a) @test addBlobentry!(v1, de1) == de1 @test addBlobentry!(dfg, :a, de2) == de2 - @test_throws ErrorException addBlobentry!(v1, de1) + @test_throws LabelExistsError addBlobentry!(v1, de1) @test de2 in getBlobentries(v1) #get @test deepcopy(de1) == getBlobentry(v1, :key1) @test deepcopy(de2) == getBlobentry(dfg, :a, :key2) - @test_throws KeyError getBlobentry(v2, :key1) - @test_throws KeyError getBlobentry(dfg, :b, :key1) + @test_throws LabelNotFoundError getBlobentry(v2, :key1) + @test_throws LabelNotFoundError getBlobentry(dfg, :b, :key1) #update @test mergeBlobentry!(dfg, :a, de2_update) == 1 diff --git a/test/testBlocks.jl b/test/testBlocks.jl index 124135aa..c004a569 100644 --- a/test/testBlocks.jl +++ b/test/testBlocks.jl @@ -3,6 +3,8 @@ using Test using Dates using Manifolds +using DistributedFactorGraphs: LabelExistsError, LabelNotFoundError + import Base: convert # import DistributedFactorGraphs: getData, addData!, updateData!, deleteData! @@ -82,7 +84,6 @@ TestCCW{T}() where {T} = TestCCW(T()) Base.:(==)(a::TestCCW, b::TestCCW) = a.usrfnc! == b.usrfnc! -DFG.getFactorOperationalMemoryType(par::NoSolverParams) = TestCCW DFG.rebuildFactorCache!(dfg::AbstractDFG{NoSolverParams}, fac::FactorCompute) = fac function DFG.reconstFactorData( @@ -469,23 +470,22 @@ function VariablesandFactorsCRUD_SET!(fg, v1, v2, v3, f0, f1, f2) # test getindex @test getLabel(fg[getLabel(v1)]) == getLabel(v1) - #TODO standardize this error and res also for that matter fnope = FactorCompute(:broken, [:a, :nope], TestFunctorInferenceType1()) - @test_throws KeyError addFactor!(fg, fnope) + @test_throws LabelNotFoundError addFactor!(fg, fnope) @test addFactor!(fg, f1) == f1 - @test_throws ErrorException addFactor!(fg, f1) + @test_throws LabelExistsError addFactor!(fg, f1) @test getLabel(fg[getLabel(f1)]) == getLabel(f1) @test mergeVariable!(fg, v3) == 1 @test mergeVariable!(fg, v3) == 1 - @test_throws ErrorException addVariable!(fg, v3) + @test_throws LabelExistsError addVariable!(fg, v3) @test mergeFactor!(fg, f2) == 1 @test mergeFactor!(fg, f2) == 1 - @test_throws ErrorException addFactor!(fg, f2) - #TODO Graphs.jl, but look at refactoring absract @test_throws ErrorException addFactor!(fg, f2) + @test_throws LabelExistsError addFactor!(fg, f2) + #TODO Graphs.jl, but look at refactoring absract @test_throws LabelExistsError addFactor!(fg, f2) if f2 isa FactorCompute f2_mod = FactorCompute( @@ -522,14 +522,14 @@ function VariablesandFactorsCRUD_SET!(fg, v1, v2, v3, f0, f1, f2) delfacCompare = getFactor(fg, :bcf1) ndel = deleteVariable!(fg, v3) @test ndel == 2 - @test_throws ErrorException deleteVariable!(fg, v3) + @test_throws LabelNotFoundError deleteVariable!(fg, v3) @test setdiff(ls(fg), [:a, :b]) == [] @test addVariable!(fg, v3) === v3 @test addFactor!(fg, f2) === f2 @test deleteFactor!(fg, f2) == 1 - @test_throws ErrorException deleteFactor!(fg, f2) + @test_throws LabelNotFoundError deleteFactor!(fg, f2) @test lsf(fg) == [:abf1] delvarCompare = getVariable(fg, :c) @@ -544,7 +544,7 @@ function VariablesandFactorsCRUD_SET!(fg, v1, v2, v3, f0, f1, f2) if isa(v1, VariableCompute) #TODO decide if this should be @error or other type - @test_throws ErrorException getVariable(fg, :a, :missingfoo) + @test_throws LabelNotFoundError getVariable(fg, :a, :missingfoo) else @test_logs (:warn, r"supported for type VariableCompute") getVariable( fg, @@ -555,12 +555,12 @@ function VariablesandFactorsCRUD_SET!(fg, v1, v2, v3, f0, f1, f2) @test getFactor(fg, :abf1) == f1 - @test_throws ErrorException getVariable(fg, :c) - @test_throws ErrorException getFactor(fg, :bcf1) + @test_throws LabelNotFoundError getVariable(fg, :c) + @test_throws LabelNotFoundError getFactor(fg, :bcf1) #test issue #375 - @test_throws ErrorException getVariable(fg, :abf1) - @test_throws ErrorException getFactor(fg, :a) + @test_throws LabelNotFoundError getVariable(fg, :abf1) + @test_throws LabelNotFoundError getFactor(fg, :a) # Existence @test exists(fg, :a) @@ -646,7 +646,7 @@ function PPETestBlock!(fg, v1) @test getLastUpdatedTimestamp(ppe) === ppe.lastUpdatedTimestamp @test addPPE!(fg, :a, ppe) == ppe - @test_throws ErrorException addPPE!(fg, :a, ppe) + @test_throws LabelExistsError addPPE!(fg, :a, ppe) @test listPPEs(fg, :a) == [:default] @@ -660,7 +660,7 @@ function PPETestBlock!(fg, v1) # Delete it @test deletePPE!(fg, :a, :default) == 1 - @test_throws KeyError getPPE(fg, :a, :default) + @test_throws LabelNotFoundError getPPE(fg, :a, :default) # Update add it @test @test_logs (:warn, Regex("'$(ppe.solveKey)' does not exist")) match_mode = :any updatePPE!( fg, @@ -687,7 +687,7 @@ function PPETestBlock!(fg, v1) #FIXME copied from lower # @test @test_deprecated getVariablePPEs(v1) == v1.ppeDict - @test_throws KeyError getPPE(v1, :notfound) + @test_throws LabelNotFoundError getPPE(v1, :notfound) #TODO # @test_deprecated getVariablePPE(v1) @@ -781,7 +781,7 @@ function VSDTestBlock!(fg, v1) # vnd.bw[1] = [1.0;] @test addVariableState!(fg, :a, vnd) == vnd - @test_throws ErrorException addVariableState!(fg, :a, vnd) + @test_throws LabelExistsError addVariableState!(fg, :a, vnd) @test issetequal(listVariableStates(fg, :a), [:default, :parametric]) @@ -819,7 +819,7 @@ function VSDTestBlock!(fg, v1) # Delete parametric from v1 @test deleteVariableState!(fg, :a, :parametric) == 1 - @test_throws KeyError getVariableState(fg, :a, :parametric) + @test_throws LabelNotFoundError getVariableState(fg, :a, :parametric) #FIXME copied from lower @test getVariableState(v1) === v1.solverDataDict[:default] @@ -877,7 +877,7 @@ function smallDataTestBlock!(fg) @test addMetadata!(fg, :a, :g => ["yes", "maybe"]) == getVariable(fg, :a).smallData @test addMetadata!(fg, :a, :h => [true, false]) == getVariable(fg, :a).smallData - @test_throws ErrorException addMetadata!(fg, :a, :a => 3) + @test_throws LabelExistsError addMetadata!(fg, :a, :a => 3) @test updateMetadata!(fg, :a, :a => 3) == getVariable(fg, :a).smallData @test_throws MethodError addMetadata!(fg, :a, :no => 0x01) @@ -967,14 +967,14 @@ function DataEntriesTestBlock!(fg, v2) v1 = getVariable(fg, :a) @test addBlobentry!(v1, de1) == de1 @test addBlobentry!(fg, :a, de2) == de2 - @test_throws ErrorException addBlobentry!(v1, de1) + @test_throws LabelExistsError addBlobentry!(v1, de1) @test de2 in getBlobentries(v1) #get @test deepcopy(de1) == getBlobentry(v1, :key1) @test deepcopy(de2) == getBlobentry(fg, :a, :key2) - @test_throws KeyError getBlobentry(v2, :key1) - @test_throws KeyError getBlobentry(fg, :b, :key1) + @test_throws LabelNotFoundError getBlobentry(v2, :key1) + @test_throws LabelNotFoundError getBlobentry(fg, :b, :key1) #update @test mergeBlobentry!(fg, :a, de2_update) == 1 @@ -1056,14 +1056,14 @@ function blobsStoresTestBlock!(fg) @test addBlobentry!(var1, de1) == de1 mergeVariable!(fg, var1) @test addBlobentry!(fg, :a, de2) == de2 - @test_throws ErrorException addBlobentry!(var1, de1) + @test_throws LabelExistsError addBlobentry!(var1, de1) @test de2 in getBlobentries(fg, var1.label) #get @test deepcopy(de1) == getBlobentry(var1, :label1) @test deepcopy(de2) == getBlobentry(fg, :a, :label2) - @test_throws KeyError getBlobentry(var2, :label1) - @test_throws KeyError getBlobentry(fg, :b, :label1) + @test_throws LabelNotFoundError getBlobentry(var2, :label1) + @test_throws LabelNotFoundError getBlobentry(fg, :b, :label1) #update @test mergeBlobentry!(fg, :a, de2_update) == 1 @@ -1316,7 +1316,7 @@ function testGroup!(fg, v1, v2, f0, f1) #solver data is initialized @test !isInitialized(fg, :a) @test !isInitialized(v2) - @test @test_logs (:error, r"does not have solver data") !isInitialized(v2, :second) + @test_throws LabelNotFoundError isInitialized(v2, :second) # solvables @test getSolvable(v1) == 0 @@ -1746,18 +1746,18 @@ function CopyFunctionsTest(testDFGAPI; kwargs...) @test issetequal(lsf(dcdfg_part), [:x2x3f1]) # not found errors - @test_throws ErrorException deepcopyGraph(GraphsDFG, dfg, [:x1, :a]) - @test_throws ErrorException deepcopyGraph(GraphsDFG, dfg, [:x1], [:f1]) + @test_throws LabelNotFoundError deepcopyGraph(GraphsDFG, dfg, [:x1, :a]) + @test_throws LabelNotFoundError deepcopyGraph(GraphsDFG, dfg, [:x1], [:f1]) # already exists errors dcdfg_part = deepcopyGraph(GraphsDFG, dfg, [:x1, :x2, :x3], [:x1x2f1, :x2x3f1]) - @test_throws ErrorException deepcopyGraph!( + @test_throws LabelExistsError deepcopyGraph!( dcdfg_part, dfg, [:x4, :x2, :x3], [:x1x2f1, :x2x3f1], ) - @test_throws ErrorException deepcopyGraph!(dcdfg_part, dfg, [:x1x2f1]) + @test_throws LabelNotFoundError deepcopyGraph!(dcdfg_part, dfg, [:x1x2f1]) # same but overwrite destination deepcopyGraph!(