Skip to content

Commit 03c53b7

Browse files
feat: handle plugin match panics (#220)
fixes #205
1 parent 54b462b commit 03c53b7

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

anyrun-macros/src/lib.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,32 @@ pub fn get_matches(_attr: TokenStream, item: TokenStream) -> TokenStream {
8585
}
8686
};
8787
quote! {
88-
if let ::core::option::Option::Some(data) = #data {
89-
#fn_name(input, data)
90-
} else {
91-
::abi_stable::std_types::RVec::new()
88+
match ::std::panic::catch_unwind(|| {
89+
if let ::core::option::Option::Some(data) = #data {
90+
#fn_name(input, data)
91+
} else {
92+
::abi_stable::std_types::RVec::new()
93+
}
94+
}
95+
) {
96+
::core::result::Result::Ok(result) => result,
97+
::core::result::Result::Err(_) => {
98+
::std::eprintln!("Plugin '{}' panicked", anyrun_internal_info().name);
99+
::abi_stable::std_types::RVec::new()
100+
}
92101
}
93102
}
94103
} else {
95104
quote! {
96-
#fn_name(input)
105+
match ::std::panic::catch_unwind(|| {
106+
#fn_name(input)
107+
}) {
108+
::core::result::Result::Ok(result) => result,
109+
::core::result::Result::Err(_) => {
110+
::std::eprintln!("Plugin '{}' panicked", anyrun_internal_info().name);
111+
::abi_stable::std_types::RVec::new()
112+
}
113+
}
97114
}
98115
};
99116

0 commit comments

Comments
 (0)