Skip to content

Commit cb9f5d7

Browse files
authored
Enhance error handling in FactorDFG and VariableDFG constructors (#1238)
* Enhance error handling in FactorDFG and VariableDFG constructors; ensure unique variable orders and proper tag initialization
1 parent 7448d2e commit cb9f5d7

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/entities/Factor.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,26 @@ function FactorDFG(
128128
timestamp = TimeDateZone(timestamp.utc_datetime)
129129
end
130130

131+
#TODO move to core constructor
132+
if !isempty(multihypo) && length(multihypo) != length(variableorder)
133+
throw(
134+
ArgumentError(
135+
"multihypo length ($(length(multihypo))) must match the number of variables ($(length(variableorder))). " *
136+
"See fractional data-association uncertainty docs.",
137+
),
138+
)
139+
end
140+
if length(variableorder) == 1 && observation isa AbstractRelativeObservation
141+
throw(
142+
ArgumentError(
143+
"Relative observation $(typeof(observation)) requires at least two variables, but only one was provided: $variableorder. Use a subtype of AbstractPriorObservation for single-variable factors.",
144+
),
145+
)
146+
end
147+
allunique(variableorder) || throw(
148+
ArgumentError("Variable order must be unique, got duplicates in $variableorder"),
149+
)
150+
131151
# create factor data
132152
hyper = Recipehyper(; multihypo, nullhypo, inflation)
133153
state = Recipestate()

src/entities/Variable.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ function VariableDFG(
124124
if solvable isa Int
125125
solvable = Ref(solvable)
126126
end
127+
tags = tags isa Set ? tags : Set{Symbol}(tags)
127128
union!(tags, [:VARIABLE])
128129

129130
P = getPointType(T)

src/services/compare.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ function compareVariable(
215215
union!(skiplist, skip)
216216
# TP = TP && compareAll(A.states, B.states; skip = skiplist, show = show)
217217

218-
Ad = getState(A, :default) #FIXME why onlly comparing default?
218+
#FIXME why only comparing hardcoded default?
219+
if !hasState(A, :default) && !hasState(B, :default)
220+
return false
221+
end
222+
Ad = getState(A, :default)
219223
Bd = getState(B, :default)
220224

221225
# TP = TP && compareAll(A.attributes, B.attributes, skip=[:variableType;], show=show)

0 commit comments

Comments
 (0)