Skip to content

Commit fcfc70f

Browse files
committed
fix Cause#FatalCause formatting.
1 parent 168dd9c commit fcfc70f

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

fvm/src/call_manager/backtrace.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,8 @@ pub struct SyscallCause {
112112

113113
#[derive(Clone, Debug)]
114114
pub struct FatalCause {
115-
/// The error message from the error.
115+
/// The alternate-formatted message from the anyhow error.
116116
pub error_msg: String,
117-
/// The original cause that initiated the error chain.
118-
pub root_cause: String,
119117
/// The backtrace, captured if the relevant
120118
/// [environment variables](https://doc.rust-lang.org/std/backtrace/index.html#environment-variables) are enabled.
121119
pub backtrace: String,
@@ -144,8 +142,7 @@ impl Cause {
144142
/// Records a fatal error as the cause of a backtrace.
145143
pub fn from_fatal(err: anyhow::Error) -> Self {
146144
Self::Fatal(FatalCause {
147-
error_msg: err.to_string(),
148-
root_cause: err.root_cause().to_string(),
145+
error_msg: format!("{:#}", err),
149146
backtrace: err.backtrace().to_string(),
150147
})
151148
}
@@ -164,8 +161,8 @@ impl Display for Cause {
164161
Cause::Fatal(msg) => {
165162
write!(
166163
f,
167-
"[FATAL] Root cause: {}, Stacktrace: {}",
168-
msg.root_cause, msg.backtrace
164+
"[FATAL] Error: {}, Backtrace:\n{}",
165+
msg.error_msg, msg.backtrace
169166
)
170167
}
171168
}

fvm/src/executor/default.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,23 @@ where
138138
}
139139
}
140140
Err(ExecutionError::Fatal(err)) => {
141-
// // Annotate the error with the message context.
142-
// let err = {
143-
// let backtrace = String::from("foo"); //e.backtrace().to_string();
144-
// // e.context(format!(
145-
// // "[from={}, to={}, seq={}, m={}, h={}] fatal error; backtrace: {}",
146-
// // msg.from,
147-
// // msg.to,
148-
// // msg.sequence,
149-
// // msg.method_num,
150-
// // self.context().epoch,
151-
// // backtrace,
152-
// // ))
153-
// };
141+
// We produce a receipt with SYS_ASSERTION_FAILED exit code, and
142+
// we consume the full gas amount so that, in case of a network-
143+
// wide fatal errors, all nodes behave deterministically.
144+
//
145+
// We set the backtrace from the fatal error to aid diagnosis.
146+
// Note that we use backtrace#set_cause instead of backtrace#begin
147+
// because we want to retain the propagation chain that we've
148+
// accumulated on the way out.
149+
let err = err.context(format!(
150+
"[from={}, to={}, seq={}, m={}, h={}]",
151+
msg.from,
152+
msg.to,
153+
msg.sequence,
154+
msg.method_num,
155+
self.context().epoch,
156+
));
154157
backtrace.set_cause(backtrace::Cause::from_fatal(err));
155-
// Produce a receipt that consumes the full gas amount.
156158
Receipt {
157159
exit_code: ExitCode::SYS_ASSERTION_FAILED,
158160
return_data: Default::default(),

0 commit comments

Comments
 (0)