Skip to content

Commit

Permalink
Create Interrupts for ScriptError
Browse files Browse the repository at this point in the history
Signed-off-by: Eval EXEC <[email protected]>
  • Loading branch information
eval-exec committed Nov 26, 2024
1 parent b861c56 commit 5f70ba5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions error/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
11 changes: 7 additions & 4 deletions script/src/error.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -183,9 +187,8 @@ impl ScriptError {
impl From<TransactionScriptError> 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),
}
}
Expand Down
1 change: 1 addition & 0 deletions script/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,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),
};

Expand Down
7 changes: 5 additions & 2 deletions script/src/verify/tests/ckb_latest/features_since_v2023.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 5f70ba5

Please sign in to comment.