I have written a native Node module using Rust + Neon Bindings. The general purpose is to query a database, decrypt the results, and return a JSON array to Node. For some datasets this is working as expected, however for others it is causing a panic. I am attempting to debug it, however I can't figure out how to get a stacktrace. The only output is:
fatal runtime error: failed to initiate panic, error 5
Abort trap: 6
My attempts to debug include:
- including "backtrace" in the Cargo.toml
- compiling without "--release"
- setting
RUST_BACKTRACE=1andDEBUG=true - creating a
test.jsfile to print the output from the module
Build output:
> neon build
neon info running cargo
... all the compilation steps.
Finished dev [unoptimized + debuginfo] target(s) in 2m 17s
neon info generating native/index.node
Test file:
const Addon = require('./lib');
const addon = new Addon();
(async function() {
console.log(`process.env.RUST_BACKTRACE = ${process.env.RUST_BACKTRACE}`);
const i = await addon.getData(237);
console.log(i, i.length)
}());
Test output:
> RUST_BACKTRACE=1 DEBUG=true node test.js
process.env.RUST_BACKTRACE = 1
fatal runtime error: failed to initiate panic, error 5
Abort trap: 6
For other values passed to addon.getData() I get back the JSON array of data as expected. The dataset that is failing is quite large so I haven't been able to determine any differences.
> rustc --version
rustc 1.38.0 (625451e37 2019-09-23)
> cargo --version
cargo 1.38.0 (23ef9a4ef 2019-08-20)
> node --version
v11.15.0
> neon version
0.3.1
I have implemented a synchronous version of the code, as well as asynchronous using this example. The async callback is converted into a Promise in ./lib/index.js. After updating the test.js to use the synchronous version of the code, I got the following output:
(node:45229) UnhandledPromiseRejectionWarning: Error: internal error in Neon module: called `Option::unwrap()` on a `None` value
I added a bunch of println!()s to my code and was able to find the error (a missing required property on a decrypted JSON object), but was never able to get a proper stack trace. It seems like Neon must be swallowing them in the async code.