diff --git a/error/src/internal.rs b/error/src/internal.rs index 71e99cd214..f73f7103ce 100644 --- a/error/src/internal.rs +++ b/error/src/internal.rs @@ -50,6 +50,9 @@ pub enum InternalErrorKind { /// The feature is disabled or is conflicted with the configuration Config, + /// Interrupts, such as a Ctrl-C signal + Interrupts, + /// Other system error Other, } diff --git a/script/src/error.rs b/script/src/error.rs index 094671d6e3..c4778562d7 100644 --- a/script/src/error.rs +++ b/script/src/error.rs @@ -1,5 +1,5 @@ use crate::types::{ScriptGroup, ScriptGroupType}; -use ckb_error::{prelude::*, Error, ErrorKind}; +use ckb_error::{prelude::*, Error, ErrorKind, InternalErrorKind}; use ckb_types::core::{Cycle, ScriptHashType}; use ckb_types::packed::{Byte32, Script}; use ckb_vm::Error as VMInternalError; @@ -44,6 +44,10 @@ pub enum ScriptError { #[error("VM Internal Error: {0:?}")] VMInternalError(VMInternalError), + /// Interrupts, such as a Ctrl-C signal + #[error("VM Interrupts")] + Interrupts, + /// Other errors raised in script execution process #[error("Other Error: {0}")] Other(String), @@ -183,9 +187,8 @@ impl ScriptError { impl From for Error { fn from(error: TransactionScriptError) -> Self { match error.cause { - ScriptError::Other(ref reason) if reason == "stopped" => { - ErrorKind::Internal.because(error) - } + ScriptError::Interrupts => ErrorKind::Internal + .because(InternalErrorKind::Interrupts.other(ScriptError::Interrupts.to_string())), _ => ErrorKind::Script.because(error), } } diff --git a/script/src/verify.rs b/script/src/verify.rs index d20afd5ceb..3d13747eda 100644 --- a/script/src/verify.rs +++ b/script/src/verify.rs @@ -1180,6 +1180,7 @@ where let mut scheduler = Scheduler::new(tx_data, version, self.syscalls_generator.clone()); let map_vm_internal_error = |error: VMInternalError| match error { VMInternalError::CyclesExceeded => ScriptError::ExceededMaximumCycles(max_cycles), + VMInternalError::External(reason) if reason.eq("stopped") => ScriptError::Interrupts, _ => ScriptError::VMInternalError(error), }; diff --git a/script/src/verify/tests/ckb_latest/features_since_v2023.rs b/script/src/verify/tests/ckb_latest/features_since_v2023.rs index d5eb783ca0..ddb0f0627d 100644 --- a/script/src/verify/tests/ckb_latest/features_since_v2023.rs +++ b/script/src/verify/tests/ckb_latest/features_since_v2023.rs @@ -540,8 +540,11 @@ async fn check_spawn_suspend_shutdown() { .verify_complete_async(script_version, &rtx, &mut command_rx, true) .await; assert!(res.is_err()); - let err = res.unwrap_err().to_string(); - assert!(err.contains("VM Internal Error: External(\"stopped\")")); + let err = res.unwrap_err(); + assert!(err.to_string().contains("VM Interrupts")); + + let reject = ckb_types::core::tx_pool::Reject::Verification(err); + assert!(!reject.is_malformed_tx()); } #[test]