Skip to content

Commit f1076b3

Browse files
fix: improve error message for missing parameter values
1 parent ada31d0 commit f1076b3

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/systems/parameter_buffer.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function MTKParameters(
7070
end
7171
end
7272

73-
isempty(missing_params) || throw(MissingVariablesError(collect(missing_params)))
73+
isempty(missing_params) || throw(MissingParametersError(collect(missing_params)))
7474

7575
tunable_buffer = Tuple(Vector{temp.type}(undef, temp.length)
7676
for temp in ic.tunable_buffer_sizes)
@@ -575,3 +575,17 @@ function as_duals(p::MTKParameters, dualtype)
575575
discrete = dualtype.(p.discrete)
576576
return MTKParameters{typeof(tunable), typeof(discrete)}(tunable, discrete)
577577
end
578+
579+
const MISSING_PARAMETERS_MESSAGE = """
580+
Some parameters are missing from the variable map.
581+
Please provide a value or default for the following variables:
582+
"""
583+
584+
struct MissingParametersError <: Exception
585+
vars::Any
586+
end
587+
588+
function Base.showerror(io::IO, e::MissingParametersError)
589+
println(io, MISSING_PARAMETERS_MESSAGE)
590+
println(io, e.vars)
591+
end

test/mtkparameters.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ u0 = [X => 1.0]
130130
tspan = (0.0, 100.0)
131131
ps = [p => 1.0] # Value for `d` is missing
132132

133-
@test_throws ModelingToolkit.MissingVariablesError ODEProblem(sys, u0, tspan, ps)
133+
@test_throws ModelingToolkit.MissingParametersError ODEProblem(sys, u0, tspan, ps)
134134
@test_nowarn ODEProblem(sys, u0, tspan, [ps..., d => 1.0])
135135

136136
# JET tests

0 commit comments

Comments
 (0)