From bd4b09b06181093c95e865b04d4a9cdda7dd0728 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Tue, 19 May 2026 21:38:58 +0800 Subject: Conditionally disable panic unwind support for async feature --- mingling_core/src/program/once_exec.rs | 37 ++++------------------------------ 1 file changed, 4 insertions(+), 33 deletions(-) (limited to 'mingling_core/src/program/once_exec.rs') diff --git a/mingling_core/src/program/once_exec.rs b/mingling_core/src/program/once_exec.rs index b68eb01..e1c0956 100644 --- a/mingling_core/src/program/once_exec.rs +++ b/mingling_core/src/program/once_exec.rs @@ -1,8 +1,8 @@ use crate::THIS_PROGRAM; -use crate::{ - Program, ProgramCollect, RenderResult, - error::{ProgramExecuteError, ProgramPanic}, -}; +use crate::{Program, ProgramCollect, RenderResult, error::ProgramExecuteError}; + +#[cfg(not(feature = "async"))] +use crate::error::ProgramPanic; // Async program #[cfg(feature = "async")] @@ -25,11 +25,6 @@ where .downcast_ref::>() .unwrap(); - #[cfg(not(panic = "abort"))] - if program.stdout_setting.silence_panic { - std::panic::set_hook(Box::new(|_| {})); - } - f(program).await } @@ -43,33 +38,9 @@ where self.args = self.args.iter().skip(1).cloned().collect(); - #[cfg(panic = "abort")] return self .exec_wrapper(|p| async { crate::exec::exec(p).await.map_err(|e| e.into()) }) .await; - - #[cfg(not(panic = "abort"))] - match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { - self.exec_wrapper(|p| async { crate::exec::exec(p).await.map_err(|e| e.into()) }) - })) { - Ok(fut) => fut.await, - Err(panic_info) => { - let panic_payload = ProgramPanic { - payload: panic_info, - }; - - let program = THIS_PROGRAM - .get() - .unwrap() - .as_ref() - .unwrap() - .downcast_ref::>() - .unwrap(); - - program.run_hook_exec_panic(&panic_payload); - Err(ProgramExecuteError::Panic(panic_payload)) - } - } } /// Run the command line program -- cgit