Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit dcb5840

Browse files
authored
add correct function name in catch_panic macro (#703)
1 parent 067c248 commit dcb5840

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

sqld-libsql-bindings/src/wal_hook.rs

+28-26
Original file line numberDiff line numberDiff line change
@@ -197,24 +197,26 @@ impl<T: WalHook> WalMethodsHook<T> {
197197
}
198198

199199
macro_rules! catch_panic {
200-
($($body:tt)*) => {
201-
let ret = catch_unwind(move || {
202-
$($body)*
203-
});
204-
205-
match ret {
206-
Ok(x) => x,
207-
Err(e) => {
208-
let error = if let Some(s) = e.downcast_ref::<String>() {
209-
s.as_str()
210-
} else if let Some(s) = e.downcast_ref::<&str>() {
211-
s
212-
} else {
213-
"unknown"
214-
};
215-
let bt = std::backtrace::Backtrace::force_capture();
216-
tracing::error!("panic in call to xframe: {error}:\n{bt}");
217-
resume_unwind(e)
200+
($name:literal, { $($body:tt)* }) => {
201+
{
202+
let ret = catch_unwind(move || {
203+
$($body)*
204+
});
205+
206+
match ret {
207+
Ok(x) => x,
208+
Err(e) => {
209+
let error = if let Some(s) = e.downcast_ref::<String>() {
210+
s.as_str()
211+
} else if let Some(s) = e.downcast_ref::<&str>() {
212+
s
213+
} else {
214+
"unknown"
215+
};
216+
let bt = std::backtrace::Backtrace::force_capture();
217+
tracing::error!("panic in call to {}: {error}:\n{bt}", $name);
218+
resume_unwind(e)
219+
}
218220
}
219221
}
220222
};
@@ -320,13 +322,13 @@ pub extern "C" fn xUndo<T: WalHook>(
320322
func: Option<unsafe extern "C" fn(*mut c_void, u32) -> i32>,
321323
undo_ctx: *mut c_void,
322324
) -> i32 {
323-
catch_panic! {
325+
catch_panic!("xUndo", {
324326
assert!(!wal.is_null());
325327
let wal = unsafe { &mut *wal };
326328
let orig_methods = get_orig_methods::<T>(wal);
327329
let orig_xundo = orig_methods.xUndo.unwrap();
328330
T::on_undo(wal, func, undo_ctx, orig_xundo)
329-
}
331+
})
330332
}
331333

332334
#[allow(non_snake_case)]
@@ -337,12 +339,12 @@ pub extern "C" fn xSavepoint<T: WalHook>(wal: *mut Wal, wal_data: *mut u32) {
337339

338340
#[allow(non_snake_case)]
339341
pub extern "C" fn xSavepointUndo<T: WalHook>(wal: *mut Wal, wal_data: *mut u32) -> i32 {
340-
catch_panic! {
342+
catch_panic!("xSavepointUndo", {
341343
let wal = unsafe { &mut *wal };
342344
let orig_methods = get_orig_methods::<T>(wal);
343345
let orig_xsavepointundo = orig_methods.xSavepointUndo.unwrap();
344346
T::on_savepoint_undo(wal, wal_data, orig_xsavepointundo)
345-
}
347+
})
346348
}
347349

348350
#[allow(non_snake_case)]
@@ -354,7 +356,7 @@ pub extern "C" fn xFrames<T: WalHook>(
354356
is_commit: c_int,
355357
sync_flags: c_int,
356358
) -> c_int {
357-
catch_panic! {
359+
catch_panic!("xFrames", {
358360
assert!(!wal.is_null());
359361
let wal = unsafe { &mut *wal };
360362
let orig_methods = get_orig_methods::<T>(wal);
@@ -369,7 +371,7 @@ pub extern "C" fn xFrames<T: WalHook>(
369371
sync_flags,
370372
orig_xframe,
371373
)
372-
}
374+
})
373375
}
374376

375377
#[tracing::instrument(skip(wal, db))]
@@ -386,7 +388,7 @@ pub extern "C" fn xCheckpoint<T: WalHook>(
386388
frames_in_wal: *mut c_int,
387389
backfilled_frames: *mut c_int,
388390
) -> i32 {
389-
catch_panic! {
391+
catch_panic!("xCheckpoint", {
390392
let wal = unsafe { &mut *wal };
391393
let orig_methods = get_orig_methods::<T>(wal);
392394
let orig_xcheckpoint = orig_methods.xCheckpoint.unwrap();
@@ -403,7 +405,7 @@ pub extern "C" fn xCheckpoint<T: WalHook>(
403405
backfilled_frames,
404406
orig_xcheckpoint,
405407
)
406-
}
408+
})
407409
}
408410

409411
#[allow(non_snake_case)]

0 commit comments

Comments
 (0)