Skip to content

Commit 8fba59a

Browse files
committed
Add warning if property could not be found or set in setAll!
1 parent c1bb2a8 commit 8fba59a

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/RecoPlans/RecoPlans.jl

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,21 @@ export setAll!
131131
132132
Recursively set the property `name` of each nested `RecoPlan` of `plan` to `x`.
133133
"""
134-
function setAll!(plan::RecoPlan{T}, name::Symbol, x) where {T<:AbstractImageReconstructionParameters}
134+
function setAll!(plan::AbstractRecoPlan, name::Symbol, x)
135+
set = Ref(false)
136+
found = Ref(false)
137+
setAll!(plan, name, x, set, found)
138+
if !set[]
139+
if !found[]
140+
@warn "Could not set all `$name` properties of plan: Property not found"
141+
else
142+
@warn "Could not set all `$name` properties of plan: Property of type $(typeof(x)) cannot be converted to the correct type"
143+
end
144+
end
145+
return nothing
146+
end
147+
148+
function setAll!(plan::RecoPlan{T}, name::Symbol, x, set, found) where {T<:AbstractImageReconstructionParameters}
135149
fields = getfield(plan, :values)
136150

137151
# Filter out nested plans
@@ -142,21 +156,23 @@ function setAll!(plan::RecoPlan{T}, name::Symbol, x) where {T<:AbstractImageReco
142156

143157
# Recursively call setAll! on nested plans
144158
for (key, nested) in nestedPlans
145-
key != name && setAll!(Observables.to_value(nested), name, x)
159+
key != name && setAll!(Observables.to_value(nested), name, x, set, found)
146160
end
147161

148162
# Set the value of the field
149163
if hasproperty(plan, name)
150164
try
165+
found[] |= true
151166
Base.setproperty!(plan, name, x)
167+
set[] |= true
152168
catch ex
153-
@error ex
154169
@warn "Could not set $name of $T with value of type $(typeof(x))"
155170
end
156171
end
172+
return nothing
157173
end
158-
setAll!(plans::AbstractArray{<:AbstractRecoPlan}, name::Symbol, x) = foreach(p -> setAll!(p, name, x), plans)
159-
setAll!(plan::RecoPlan{<:AbstractImageReconstructionAlgorithm}, name::Symbol, x) = setAll!(plan.parameter, name, x)
174+
setAll!(plans::AbstractArray{<:AbstractRecoPlan}, name::Symbol, args...) = foreach(p -> setAll!(p, name, args...), plans)
175+
setAll!(plan::RecoPlan{<:AbstractImageReconstructionAlgorithm}, name::Symbol, args...) = setAll!(plan.parameter, name, args...)
160176
"""
161177
setAll!(plan::AbstractRecoPlan; kwargs...)
162178

0 commit comments

Comments
 (0)