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

Better error handling for callbacks

Open aviks opened this issue 6 years ago • 0 comments

When the programmer makes a mistake in the number of arguments for a callback, the error message is very dificult to parse. In a large app with many callbacks, it will be impossible to understand where the error is coming from.

In the code below, the callid is defined with 2 inputs, but the function itself has only one argument. That throws the error below at runtime.

app = Dash("Test App") do
   html_div() do
     dcc_slider(id="n", min=1, max=10, value=2),
     html_button("Submit", id="submit_button", n_clicks=0),
     html_span("0", id="outval")
   end
end;

callback!(app, callid"{n.value} submit_button.n_clicks => outval.children") do N
  N
end
┌ Error: error handling request
│   exception =
│    MethodError: no method matching (::var"#17#18")(::Int64, ::Int64)
│    Closest candidates are:
│      #17(::Any) at untitled-7814016ae0f6e59fe06df0f4913896fc:41
│    Stacktrace:
│     [1] (::Dashboards.var"#455#456"{Bool,Dash})(::HTTP.Messages.Request) at C:\Users\avik\.julia\packages\Dashboards\hn9XK\src\Dashboards.jl:439
│     [2] handle at C:\Users\avik\.julia\packages\HTTP\hJSsm\src\Handlers.jl:253 [inlined]
│     [3] handle(::HTTP.Handlers.RequestHandlerFunction{Dashboards.var"#455#456"{Bool,Dash}}, ::HTTP.Streams.Stream{HTTP.Messages.Request,HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}}) at C:\Users\avik\.julia\packages\HTTP\hJSsm\src\Handlers.jl:276
│     [4] #4 at C:\Users\avik\.julia\packages\HTTP\hJSsm\src\Handlers.jl:345 [inlined]
│     [5] macro expansion at C:\Users\avik\.julia\packages\HTTP\hJSsm\src\Servers.jl:360 [inlined]
│     [6] (::HTTP.Servers.var"#13#14"{HTTP.Handlers.var"#4#5"{HTTP.Handlers.RequestHandlerFunction{Dashboards.var"#455#456"{Bool,Dash}}},HTTP.ConnectionPool.Transaction{Sockets.TCPSocket},HTTP.Streams.Stream{HTTP.Messages.Request,HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}}})() at .\task.jl:333
└ @ HTTP.Servers C:\Users\avik\.julia\packages\HTTP\hJSsm\src\Servers.jl:364

aviks avatar Nov 06 '19 23:11 aviks