Skip to content

Commit

Permalink
raise fatal Errors with rb_exc_fatal
Browse files Browse the repository at this point in the history
so they can't be rescued
  • Loading branch information
matsadler committed Sep 14, 2024
1 parent 52a0817 commit 65e35e5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
### Removed

### Fixed
- The `fatal` exception raised when a Rust function bound to Ruby panics can no
longer be caught with `rescue Exception`.

### Security

Expand Down
13 changes: 11 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use std::{any::Any, borrow::Cow, ffi::CString, fmt, mem::transmute, os::raw::c_int};

use rb_sys::{
rb_bug, rb_ensure, rb_errinfo, rb_exc_raise, rb_iter_break_value, rb_jump_tag, rb_protect,
rb_set_errinfo, rb_warning, ruby_special_consts, VALUE,
rb_bug, rb_ensure, rb_errinfo, rb_exc_fatal, rb_exc_raise, rb_iter_break_value, rb_jump_tag,
rb_protect, rb_set_errinfo, rb_warning, ruby_special_consts, VALUE,
};

use crate::{
Expand Down Expand Up @@ -539,6 +539,15 @@ where
pub(crate) fn raise(e: Error) -> ! {
match e.0 {
ErrorType::Jump(tag) => tag.resume(),
ErrorType::Error(class, _)
if class.as_rb_value()
== unsafe { Ruby::get_unchecked().exception_fatal().as_rb_value() } =>
{
unsafe { rb_exc_fatal(e.exception().as_rb_value()) }
// friendly reminder: we really never get here, and as such won't
// drop any values still in scope, make sure everything has been
// consumed/dropped
}
_ => {
unsafe { rb_exc_raise(e.exception().as_rb_value()) }
// friendly reminder: we really never get here, and as such won't
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@
//! * `rb_eval_string`: See [`eval()`] or [`eval!`].
//! * `rb_eval_string_protect`: [`eval()`] or [`eval!`].
// * `rb_eval_string_wrap`:
// * `rb_exc_fatal`:
//! * `rb_exc_fatal`: Return an [`Error`] constructed from [`Ruby::exception_fatal`].
// * `rb_exc_new`:
// * `rb_exc_new_cstr`:
// * `rb_exc_new_str`:
Expand Down

0 comments on commit 65e35e5

Please sign in to comment.