Mimi Framework

Improve Missing Data Error Message

I accidentally tried to use a value that didn’t exist yet. If the error message gave a bit more detail (i.e. “You gave the X component a value for the Y parameter that doesn’t exist in timestep Z”) that would make hunting bugs much easier.

Here’s the error message I received:

ERROR: MissingException: Cannot get index; data is missing. You may have tried to access a value that has not yet been computed.
Stacktrace:
 [1] _missing_data_check(::Missing) at C:\Users\Frank Errickson\.julia\packages\Mimi\fpiRX\src\core\time.jl:192
 [2] getindex at C:\Users\Frank Errickson\.julia\packages\Mimi\fpiRX\src\core\time.jl:222 [inlined]
 [3] run_timestep_rf_ch4_etminan(::Mimi.ComponentInstanceParameters{NamedTuple{(:a₃, :b₃, :N₂O_0, :scale_CH₄, :CH₄_0, :N₂O, :CH₄),Tuple{Mimi.ScalarModelParameter{Float64},Mimi.ScalarModelParameter{Float64},Mimi.ScalarModelParameter{Float64},Mimi.ScalarModelParameter{Float64},Mimi.ScalarModelParameter{Float64},Mimi.TimestepArray{Mimi.FixedTimestep{1765,1,LAST} where LAST,Float64,1,1},Mimi.TimestepArray{Mimi.FixedTimestep{1765,1,LAST} where LAST,Union{Missing, Float64},1,1}}}}, ::Mimi.ComponentInstanceVariables{NamedTuple{(:rf_CH₄,),Tuple{Mimi.TimestepArray{Mimi.FixedTimestep{1765,1,LAST} where LAST,Union{Missing, Float64},1,1}}}}, ::Mimi.DimDict, ::Mimi.FixedTimestep{1765,1,2300}) at C:\Users\Frank Errickson\.julia\packages\Mimi\fpiRX\src\core\defcomp.jl:21
 [4] run_timestep(::Mimi.ComponentInstance{Mimi.ComponentInstanceVariables{NamedTuple{(:rf_CH₄,),Tuple{Mimi.TimestepArray{Mimi.FixedTimestep{1765,1,LAST} where LAST,Union{Missing, Float64},1,1}}}},Mimi.ComponentInstanceParameters{NamedTuple{(:a₃, :b₃, :N₂O_0, :scale_CH₄, :CH₄_0, :N₂O, :CH₄),Tuple{Mimi.ScalarModelParameter{Float64},Mimi.ScalarModelParameter{Float64},Mimi.ScalarModelParameter{Float64},Mimi.ScalarModelParameter{Float64},Mimi.ScalarModelParameter{Float64},Mimi.TimestepArray{Mimi.FixedTimestep{1765,1,LAST} where LAST,Float64,1,1},Mimi.TimestepArray{Mimi.FixedTimestep{1765,1,LAST} where LAST,Union{Missing, Float64},1,1}}}}}, ::Mimi.Clock{Mimi.FixedTimestep}) at C:\Users\Frank Errickson\.julia\packages\Mimi\fpiRX\src\core\instances.jl:264
 [5] _run_components(::Mimi.ModelInstance, ::Mimi.Clock{Mimi.FixedTimestep}, ::Array{Int64,1}, ::Array{Int64,1}, ::Array{Mimi.Clock{Mimi.FixedTimestep},1}) at C:\Users\Frank Errickson\.julia\packages\Mimi\fpiRX\src\core\instances.jl:277
 [6] run(::Mimi.ModelInstance, ::Int64, ::Nothing) at C:\Users\Frank Errickson\.julia\packages\Mimi\fpiRX\src\core\instances.jl:313
 [7] #run#116(::Int64, ::Nothing, ::typeof(run), ::Model) at C:\Users\Frank Errickson\.julia\packages\Mimi\fpiRX\src\core\model.jl:399
 [8] run(::Model) at C:\Users\Frank Errickson\.julia\packages\Mimi\fpiRX\src\core\model.jl:390
 [9] top-level scope at REPL[6]:100:

Unfortunately it isn’t possible to include the component or parameter names in the error message at the moment, because those aren’t available to the function at that time (but I’ll look into how we may be able to change that). For now that information would need to be found in the Stacktrace, as listed above, but I could certainly included the timestep information! I’ll start an issue for this here: https://github.com/mimiframework/Mimi.jl/issues/555

We will also be working on getting the Stacktrace line number to come out correctly so you can pinpoint the line within your file that is throwing the error.

@lrennels, can you open an issue for the stack trace stuff? Thanks!

@davidanthoff It seems like we thought we fixed this … https://github.com/mimiframework/Mimi.jl/issues/374@FrankErrickson on what line in your component were you causing this error?

Here’s the closed merged PR for the fix back in February: https://github.com/mimiframework/Mimi.jl/pull/404

@lrennels Sorry, I don’t remember the line number. I think my main issue was the Stacktrace can be a bit opaque, certainly for people new to coding or Mimi. This was a relatively simple model, and even with the Stacktrace info it still took a while to track down where the error came from. I think I was being overly optimistic and hoping Mimi could just shine a big spotlight on my error!

No problem! As of now it’s structurally not possible for us to shine a big spotlight but I can certainly at least tell you what the tilmestep is, and then hopefully the Stacktfrace would give you a component name and a line number if you look at it carefully. Agreed it can be opaque for new coders, luckily Julia is working hard a new debugger so you can step through your code and that will make debugging far easier!