Stipple.jl
Stipple.jl copied to clipboard
@event does not propagate errors
When an error happens within an @event block, it is not printed and the block fails silently.
MWE:
using GenieFramework
@genietools
@app begin
@in error = false
@onbutton error begin
println("Error ")
a = nonexistantvar
println("This will never be printed")
end
@event :error_event begin
println("Error event")
a = nonexistantvar
println("This will never be printed")
end
end
ui() = btn("Error 1", @click(:error)) * btn("Error 2", @on(:click, :error_event))
@page("/", ui)
up()
This is what is printed to the REPL:
Error
┌ Warning: 2024-08-06 10:42:01 UndefVarError(:nonexistantvar)
└ @ Stipple ~/.julia/packages/Stipple/Hr6Qa/src/Stipple.jl:999
Error event
@PGimenez The error is printed (granted as a warning) though? What would you expect to happen?
@PGimenez The error is printed (granted as a warning) though? What would you expect to happen?
I'm talking about the @event block. it prints Error event but it doesnt show an error when executing the a=nonexisttantvarline
I don't get it... it says here:
┌ Warning: 2024-08-06 10:42:01 UndefVarError(:nonexistantvar)
└ @ Stipple ~/.julia/packages/Stipple/Hr6Qa/src/Stipple.jl:999
Ah, that's from the other one... Thanks for making the example more complicated 😂
I saw a comment from @olivierlabayle here on the difficulty of debugging, i think it has been deleted. Anyhow, there are three important ways of debugging that I want to mention in this context:
- add try catch in your event handler
- call the event handler directly via
notify(model, Val(:myevent), event). If your handler uses the event you must contruct it appropriately. - If it is about calling an
@onchangehandler you can do that viaStipple.debug(model, :myvar, newvalue), you can even execute handlers with a certain priority.
For cases 2 and 3 you need to make the model available in your context, either by global model = @init in the route or by @page("/", ui, model = MyApp, post = x -> (global model = x; nothing)). The docstring on this function shows a variety of examples.
BTW, if you are interested in debugging and the error message alone doesn't help you, consider the follwoing approach:
# define the event
@event :click begin
try
println("before")
non_exitisting_var
println("after")
catch e
println(e)
println.(stacktrace())
nothing
end
end
# test the event
notify(model, Val(:click), "hi")
results in
before
UndefVarError(:non_exitisting_var, 0x00000000000097d3, Main)
macro expansion at REPL[32]:8 [inlined]
notify(__model__::Main_ReactiveModel!_1, ::Val{:click}, event::Any) at ReactiveTools.jl:1436
top-level scope at REPL[34]:1
eval(m::Module, e::Any) at boot.jl:489
eval at Base_compiler.jl:146 [inlined]
repleval(m::Module, code::Expr, ::String) at repl.jl:229
#evalrepl##2 at repl.jl:192 [inlined]
with_logstate(f::VSCodeServer.var"#evalrepl##2#evalrepl##3"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt}, logstate::Base.CoreLogging.LogState) at logging.jl:540
with_logger at logging.jl:651 [inlined]
(::VSCodeServer.var"#evalrepl##0#evalrepl##1"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})() at repl.jl:193
(::VSCodeServer.var"#start_eval_backend##0#start_eval_backend##1")() at eval.jl:34
Can we close this issue?