Stipple.jl icon indicating copy to clipboard operation
Stipple.jl copied to clipboard

@event does not propagate errors

Open PGimenez opened this issue 1 year ago • 4 comments
trafficstars

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 avatar Aug 06 '24 08:08 PGimenez

@PGimenez The error is printed (granted as a warning) though? What would you expect to happen?

essenciary avatar Aug 06 '24 12:08 essenciary

@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

PGimenez avatar Aug 06 '24 12:08 PGimenez

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

essenciary avatar Aug 06 '24 13:08 essenciary

Ah, that's from the other one... Thanks for making the example more complicated 😂

essenciary avatar Aug 06 '24 13:08 essenciary

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:

  1. add try catch in your event handler
  2. call the event handler directly via notify(model, Val(:myevent), event). If your handler uses the event you must contruct it appropriately.
  3. If it is about calling an @onchange handler you can do that via Stipple.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.

hhaensel avatar Oct 18 '25 23:10 hhaensel

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

hhaensel avatar Nov 05 '25 22:11 hhaensel

Can we close this issue?

hhaensel avatar Nov 10 '25 06:11 hhaensel