File tree Expand file tree Collapse file tree 2 files changed +10
-18
lines changed Expand file tree Collapse file tree 2 files changed +10
-18
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @rspack/binding " : patch
3+ ---
4+
5+ fix: panic hook failed to restore after being suppressed
Original file line number Diff line number Diff line change @@ -43,39 +43,26 @@ pub mod PanicStrategy {
4343
4444#[ inline]
4545fn panic_hook_handler < S : PanicStrategy :: S , R > ( f : impl FnOnce ( ) -> R ) -> R {
46- PANIC_HOOK . with ( |hook| {
47- if !S :: is_suppressed ( ) {
48- * hook. borrow_mut ( ) = Some ( std:: panic:: take_hook ( ) ) ;
49- }
50- } ) ;
46+ let prev = std:: panic:: take_hook ( ) ;
5147 std:: panic:: set_hook ( Box :: new ( move |info| {
52- PANIC_HOOK . with ( |hook| {
53- if let Some ( hook) = & * hook. borrow ( ) {
54- hook ( info) ;
55- }
56- } ) ;
5748 PANIC_INFO_AND_BACKTRACE . with ( |bt| {
5849 * bt. borrow_mut ( ) = Some ( (
5950 info. to_string ( ) ,
6051 std:: backtrace:: Backtrace :: force_capture ( ) . to_string ( ) ,
6152 ) ) ;
6253 } ) ;
54+ if !S :: is_suppressed ( ) {
55+ prev ( info) ;
56+ }
6357 } ) ) ;
6458 let result = f ( ) ;
65- PANIC_HOOK . with ( |hook| {
66- if let Some ( hook) = hook. borrow_mut ( ) . take ( ) {
67- std:: panic:: set_hook ( hook) ;
68- }
69- } ) ;
59+ let _ = std:: panic:: take_hook ( ) ;
7060
7161 result
7262}
7363
74- type PanicHook = Box < dyn Fn ( & std:: panic:: PanicInfo < ' _ > ) + ' static + Sync + Send > ;
75-
7664thread_local ! {
7765 static PANIC_INFO_AND_BACKTRACE : RefCell <Option <( String , String ) >> = RefCell :: new( None ) ;
78- static PANIC_HOOK : RefCell <Option <PanicHook >> = RefCell :: new( None ) ;
7966}
8067
8168pub fn catch_unwind < S : PanicStrategy :: S , R > ( f : impl FnOnce ( ) -> R ) -> Result < R > {
You can’t perform that action at this time.
0 commit comments