|
1 | 1 | use fvm_shared::error::ExitCode;
|
2 | 2 | use thiserror::Error;
|
3 | 3 |
|
| 4 | +mod abort { |
| 5 | + use crate::ActorError; |
| 6 | + use fvm_shared::error::ExitCode; |
| 7 | + |
| 8 | + #[derive(thiserror::Error, Debug)] |
| 9 | + #[error("abort error")] |
| 10 | + pub struct Abort { |
| 11 | + /// This ensures that this error can not be crated outside. |
| 12 | + _private: (), |
| 13 | + } |
| 14 | + |
| 15 | + #[cfg(feature = "fil-actor")] |
| 16 | + fn maybe_abort(exit_code: ExitCode, msg: Option<&str>) -> ! { |
| 17 | + fvm_sdk::vm::abort(exit_code as u32, msg); |
| 18 | + } |
| 19 | + #[cfg(not(feature = "fil-actor"))] |
| 20 | + fn maybe_abort(exit_code: ExitCode, msg: Option<&str>) -> ! { |
| 21 | + // TODO: maybe not panic, needs discussion what we want here |
| 22 | + panic!("Abort: {}: {:?}", exit_code, msg); |
| 23 | + } |
| 24 | + |
| 25 | + impl From<ActorError> for Abort { |
| 26 | + fn from(err: ActorError) -> Self { |
| 27 | + let ActorError { exit_code, msg } = err; |
| 28 | + maybe_abort(exit_code, Some(&msg)); |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + /// Converts a raw encoding error into an ErrSerialization. |
| 33 | + impl From<fvm_ipld_encoding::Error> for Abort { |
| 34 | + fn from(e: fvm_ipld_encoding::Error) -> Self { |
| 35 | + maybe_abort(ExitCode::ErrSerialization, Some(&e.to_string())); |
| 36 | + } |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +pub use abort::Abort; |
| 41 | + |
4 | 42 | /// TODO fix error system; actor errors should be transparent to the VM.
|
5 | 43 | /// The error type that gets returned by actor method calls.
|
6 | 44 | #[derive(Error, Debug, Clone, PartialEq)]
|
@@ -114,17 +152,17 @@ macro_rules! actor_error {
|
114 | 152 | macro_rules! ensure {
|
115 | 153 | ($cond:expr, $code:ident, $msg:literal $(,)?) => {
|
116 | 154 | if !$cond {
|
117 |
| - return Err($crate::actor_error!($code, $msg)); |
| 155 | + return Err($crate::actor_error!($code, $msg).into()); |
118 | 156 | }
|
119 | 157 | };
|
120 | 158 | ($cond:expr, $code:ident, $err:expr $(,)?) => {
|
121 | 159 | if !$cond {
|
122 |
| - return Err($crate::actor_error!($code, $err)); |
| 160 | + return Err($crate::actor_error!($code, $err).into()); |
123 | 161 | }
|
124 | 162 | };
|
125 | 163 | ($cond:expr, $code:ident, $fmt:expr, $($arg:tt)*) => {
|
126 | 164 | if !$cond {
|
127 |
| - return Err($crate::actor_error!($code, $fmt, $($arg)*)); |
| 165 | + return Err($crate::actor_error!($code, $fmt, $($arg)*).into()); |
128 | 166 | }
|
129 | 167 | };
|
130 | 168 | }
|
|
0 commit comments