-
Notifications
You must be signed in to change notification settings - Fork 17
Print entire cause chain in case of actor restart #1638
Conversation
Previously, the stop reason of a supervised actor only needed to implement `fmt::Display`. In practise however, we are always using an enum here that implements `std::error::Error`. The default impl of `Display` for an `Error` only prints the top-level cause. If the error contains a `cause`, it is the responsibility of the caller to walk the chain of causes and concatenate all the errors. Anyhow implements this logic for its own error type and it can be used by specifying the `alternate` modifier of `Display`: `#`. To construct an anyhow::Error, we change the trait requirements for the stop reason to implement `std::error::Error`.
d472119
to
813353a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of curiosity - how does this look like? have you managed to capture some examples is the logs? has it proven more useful?
It looks like other cause chains that we print out in the logs. They are concatenated with
|
let reason_str = msg.reason.to_string(); | ||
let should_restart = (self.restart_policy)(msg.reason); | ||
let should_restart = (self.restart_policy)(&msg.reason); | ||
let reason_str = format!("{:#}", anyhow::Error::new(msg.reason)); // Anyhow will format the entire chain of errors when using `alternate` Display (`#`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Nice trick. It's interesting that it's not easy to print the error chain without converting to anyhow::Error
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is in the works: rust-lang/project-error-handling#10 (comment)
bors r+ |
Previously, the stop reason of a supervised actor only needed to
implement
fmt::Display
. In practise however, we are always usingan enum here that implements
std::error::Error
. The default impl ofDisplay
for anError
only prints the top-level cause. If the errorcontains a
cause
, it is the responsibility of the caller to walk thechain of causes and concatenate all the errors.
Anyhow implements this logic for its own error type and it can be used
by specifying the
alternate
modifier ofDisplay
:#
.To construct an anyhow::Error, we change the trait requirements for the
stop reason to implement
std::error::Error
.