Search code examples
rustelectronneon-bindings

How to get stack backtrace from Rust addon to Electron app


I am using neon to create a Rust addon to an Electron app. It's basically working, but every time there's a crash I get an error message like "attempt to divide by zero" but no location, and as the code base grows it gets increasingly onerous to figure out where the problem is.

I tried changing the build script from

electron-build-env neon build my_addon --release

to

electron-build-env neon build my_addon

and setting the usual env var

RUST_BACKTRACE=1 my_app

but got no backtrace. I couldn't find this written up anywhere, but surely it is possible. Can anyone show me how to do this?

UPDATE: It occurs to me that when you build in debug mode, the binary goes into a different directory -- target/debug vs. target/release -- and I haven't done anything to account for that (unless "neon" vs "neon --release" does it). Grepping didn't turn up the text "target/release" anywhere.


Solution

  • I wasn't getting an answer here, so I looked around and found that there is a Neon Community on Slack and asked the question there. There kjv (K. J. Valencik, who I think is the author of neon-bindings and neon-serde) said that Neon attempts to turn panics into Javascript exceptions, sending nothing to stderr. It isn't yet clear to me whether such a Javascript exception would contain the Rust backtrace if the add-on were compiled in debug mode; there is no backtrace with release mode. To be continued....