diff --git a/actors/runtime/src/actor_error.rs b/actors/runtime/src/actor_error.rs index c7a3949d8c..4919883c51 100644 --- a/actors/runtime/src/actor_error.rs +++ b/actors/runtime/src/actor_error.rs @@ -12,6 +12,9 @@ pub struct ActorError { msg: String, } +// TODO: use symbolic constant for ErrAssertionFailed when it's defined. +pub const EXIT_CODE_ERR_ASSERTION_FAILED: ExitCode = ExitCode::new(24); + impl ActorError { /// Creates a new ActorError. This method does not check that the code is in the /// range of valid actor abort codes. @@ -44,8 +47,7 @@ impl ActorError { Self { exit_code: ExitCode::USR_UNSPECIFIED, msg } } pub fn user_assertion_failed(msg: String) -> Self { - // TODO: use symbolic constant for ErrAssertionFailed when it's defined. - Self { exit_code: ExitCode::from(24), msg } + Self { exit_code: EXIT_CODE_ERR_ASSERTION_FAILED, msg } } /// Returns the exit code of the error. diff --git a/actors/runtime/src/runtime/fvm.rs b/actors/runtime/src/runtime/fvm.rs index b922504bfa..ad502e934a 100644 --- a/actors/runtime/src/runtime/fvm.rs +++ b/actors/runtime/src/runtime/fvm.rs @@ -23,7 +23,7 @@ use fvm_shared::{ActorID, MethodNum}; use crate::runtime::actor_blockstore::ActorBlockstore; use crate::runtime::{ActorCode, ConsensusFault, MessageInfo, Policy, RuntimePolicy, Syscalls}; -use crate::{actor_error, ActorError, Runtime}; +use crate::{actor_error, ActorError, Runtime, EXIT_CODE_ERR_ASSERTION_FAILED}; lazy_static! { /// Cid of the empty array Cbor bytes (`EMPTY_ARR_BYTES`). @@ -270,6 +270,7 @@ where } else { // The returned code can't be simply propagated as it may be a system exit code. // TODO: improve propagation once we return a RuntimeError. + // Ref https://github.com/filecoin-project/builtin-actors/issues/144 Err(actor_error!( user_assertion_failed, format!( @@ -448,7 +449,7 @@ pub fn trampoline(params: u32) -> u32 { // We do this after handling the error, because the actor may have encountered an error before // it even could validate the caller. if !rt.caller_validated { - fvm::vm::abort(ExitCode::USR_UNSPECIFIED.value(), Some("failed to validate caller")) + fvm::vm::abort(EXIT_CODE_ERR_ASSERTION_FAILED, Some("failed to validate caller")) } // Then handle the return value. diff --git a/actors/runtime/src/test_utils.rs b/actors/runtime/src/test_utils.rs index 798d0067f8..33c7ab002d 100644 --- a/actors/runtime/src/test_utils.rs +++ b/actors/runtime/src/test_utils.rs @@ -785,7 +785,7 @@ impl Runtime for MockRuntime { F: FnOnce(&mut C, &mut Self) -> Result, { if self.in_transaction { - return Err(actor_error!(unspecified; "nested transaction")); + return Err(actor_error!(user_assertion_failed; "nested transaction")); } let mut read_only = self.state()?; self.in_transaction = true; @@ -810,7 +810,7 @@ impl Runtime for MockRuntime { ) -> Result { self.require_in_call(); if self.in_transaction { - return Err(actor_error!(unspecified; "side-effect within transaction")); + return Err(actor_error!(user_assertion_failed; "side-effect within transaction")); } assert!( @@ -855,7 +855,7 @@ impl Runtime for MockRuntime { fn create_actor(&mut self, code_id: Cid, actor_id: ActorID) -> Result<(), ActorError> { self.require_in_call(); if self.in_transaction { - return Err(actor_error!(unspecified; "side-effect within transaction")); + return Err(actor_error!(user_assertion_failed; "side-effect within transaction")); } let expect_create_actor = self .expectations @@ -871,7 +871,7 @@ impl Runtime for MockRuntime { fn delete_actor(&mut self, addr: &Address) -> Result<(), ActorError> { self.require_in_call(); if self.in_transaction { - return Err(actor_error!(unspecified; "side-effect within transaction")); + return Err(actor_error!(user_assertion_failed; "side-effect within transaction")); } let exp_act = self.expectations.borrow_mut().expect_delete_actor.take(); if exp_act.is_none() {