Open danielpclark opened 7 years ago
Looking at the Rust source code it looks like panics from C cannot be caught & unwound from the Rust side: https://github.com/rust-lang/rust/blob/d96cc6e2865ff2cc77f061ae97e58aae50f5a1e9/src/test/run-pass/abort-on-c-abi.rs
For this we'd likely need to use Ruby's rb_protect
to implement this, or something like this. Thoughts?
Poossibly related. When calling the Exception#full_message
method from Rust it panics.
The method:
fn full_string(&self) -> String {
RString::from(binding_util::call_method(self.value(), "full_string", None)).to_string()
}
The example:
use ruru::{AnyException, Exception, Object, VM};
# VM::init();
assert_eq!(
AnyException::new("StandardError", Some("something went wrong")).full_string(),
"StandardError: something went wrong"
);
Here's what Ruby gives you when you're in irb
:
"\e[1mTraceback \e[m(most recent call last):\n(irb):10:in `full_message': \e[1msomething went wrong (\e[4;1mStandardError\e[m\e[1m)\n\e[m"
Ruby has this particular string in it's own test suite:
https://github.com/ruby/ruby/blob/b67ead14521fb74bcf8ec28f8c78245dfb536b70/test/ruby/test_dir_m17n.rb#L72
This will cause ruru to panic:
I've tried wrapping it in a thread but that failed.
I then found Rust's std::panic::catch_unwind which according to the original RFC is meant to handle such panics from C method calls. The catch_unwind doc has this note:
I have thus far been unable to catch the panic from this and looking up the error Utf8Error it would seem that that is a side effect of the kind of methods used from libruby for RString and that error isn't written in ruru.