Description
Background
Rust driver panics in various scenarios, mainly if a bug is encountered in the driver's code or when the API is heavily misused.
Problem statement
We need to ensure that if Rust driver (or any other Rust code) panics, Undefined Behaviour is not triggered and we understand what happens.
Useful resources
FFI (Foreign Function Interface) is (most likely, let's check it) the interface that napi-rs leverages to interface with NodeJS.
When stack-unwinding panics occur and cross the language boundary, various things can happen based on used extern
ABI.
See rustonomicon for more details.
Simplest possible solution
Use panic=abort
in Cargo.toml. Then a panic, instead of unwinding, aborts the process immediately.
This has a significant disadvantage: the printed debug message is limited to only the LoC where the panic was thrown, but there is no backtrace attached. This makes debugging much harder.
Another approach, which preserves backtraces
Use panic=unwind
in Cargo.toml (the implicit default). Then a panic unwinds up until the language FFI boundary and then the program is aborted (hopefully after the backtrace is printed - let's verify that).