Open colinxs opened 5 years ago
The callbacks are run in a separate julia process which will die if there's an uncaught error. One possible solution is to try/catch any errors using standard Julia control flow (e.g., as done here) and do whatever logic you'd like (shutting down the program, printing the error and stack trace and continuing on, etc.).
Makes sense! I put together a little macro that has proved to be very useful if you (or anyone else) finds a need for it:
macro debugtask(ex)
quote
try
$(esc(ex))
catch e
bt = stacktrace(catch_backtrace())
io = IOBuffer()
showerror(io, e, bt)
errstr = String(take!(io))
RobotOS.logfatal("Error: $errstr")
exit()
end
end
end
function foo_callback(msg)
@debugtask begin
error("whoops")
end
end
Now when the error is thrown it shuts down the node and causes the error message to be logged to stderr and /rosout as one would expect in Python.
No errors are printed to stdout. Roslaunch is configured with output="screen". Here's an example (note the tools calls to error() in callback and main:
Is there any way to to have these errors raised so that the process exits? Having them fail silently makes debugging far more difficult. Thanks!