Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The called code is made unwind-safe at the FFI boundary using `std::panic::catch_unwind`. A panic will be converted to an Erlang exception.


Except it doesn't work always,

> Note that this function may not catch all panics in Rust. A panic in Rust is not always implemented via unwinding, but can be implemented by aborting the process as well. This function only catches unwinding panics, not those that abort the process.


It works whenever it's configured to unwind, which is the default. Apparently one can force this by adding a few lines in the rustler Cargo.toml (https://doc.rust-lang.org/edition-guide/rust-2018/error-hand...), I'll create a PR.


If you compile a NIF you probably will not go out of your way to write "panic = abort" in your project. Unwinding is the default behavior.


It depends on the dependencies.


From the docs filmor linked to, if a library sets panic = unwind and a user sets that to abort, “If any of your users choose to abort, they'll get a compile-time failure.”


I was thinking more about libraries that choose to abort, and already compiled.


It's considered bad practice, as far as I know. The executable should decide that, not library.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: