Skip to content

Stacktrace of error in @mtkmodel points to MTK internals rather than user code #2290

Open
@baggepinnen

Description

@baggepinnen

The new @mtkmodel macro is quite a bit nicer to work with compared to the old boilerplaty way to define models 🎉

One problem I've noticed is that when the model definition contains an error, we now get a useless stacktrace:

julia> @named model = TankWithInput()
ERROR: MethodError: no method matching /(::Num, ::ODESystem)

Closest candidates are:
  /(::Union{Num, SymbolicUtils.Symbolic}, ::Unitful.AbstractQuantity)
   @ ModelingToolkit ~/.julia/packages/ModelingToolkit/BsHty/src/systems/validation.jl:2
  /(::Number, ::DiffEqScalar)
   @ SciMLBase ~/.julia/packages/SciMLBase/szsYq/src/operators/basic_operators.jl:63
  /(::Number, ::AbstractGray)
   @ ColorVectorSpace ~/.julia/packages/ColorVectorSpace/tLy1N/src/ColorVectorSpace.jl:309
  ...

Stacktrace:
 [1] __MixingTank__(; name::Symbol, c0::Nothing, T0::Nothing, a1::Nothing, a21::Nothing, a22::Nothing, b::Nothing, k0::Nothing, eps::Nothing, gamma::Nothing, c::Nothing, T::Nothing, T_c::Nothing)
   @ Main ~/.julia/packages/ModelingToolkit/BsHty/src/systems/model_parsing.jl:82
 [2] (::ModelingToolkit.Model{typeof(__MixingTank__), Dict{Symbol, Any}})(; kw::Base.Pairs{Symbol, Symbol, Tuple{Symbol}, NamedTuple{(:name,), Tuple{Symbol}}})
   @ ModelingToolkit ~/.julia/packages/ModelingToolkit/BsHty/src/systems/model_parsing.jl:25
 [3] macro expansion
   @ ~/.julia/packages/ModelingToolkit/BsHty/src/systems/abstractsystem.jl:999 [inlined]
 [4] __TankWithInput__(; name::Symbol, in__k::Nothing)
   @ Main ~/.julia/packages/ModelingToolkit/BsHty/src/systems/model_parsing.jl:82
 [5] __TankWithInput__
   @ ~/.julia/packages/ModelingToolkit/BsHty/src/systems/model_parsing.jl:82 [inlined]
 [6] #_#172
   @ ~/.julia/packages/ModelingToolkit/BsHty/src/systems/model_parsing.jl:25 [inlined]
 [7] top-level scope
   @ ~/.julia/packages/ModelingToolkit/BsHty/src/systems/abstractsystem.jl:999

all source lines point into the internals of MTK, none of them points to the error in my source code. I believe there is a way to help the macro point to the relevant source line, but I cannot quite remember how. Errors inside Plots @recipe will at least point to the exact source line in the user defined @recipe

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions