Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Print entire cause chain in case of actor restart #1638

Merged
merged 1 commit into from
Mar 16, 2022

Conversation

thomaseizinger
Copy link
Contributor

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.

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`.
@thomaseizinger thomaseizinger force-pushed the chore/print-entire-reason-for-restart branch from d472119 to 813353a Compare March 15, 2022 05:25
Copy link
Contributor

@klochowicz klochowicz left a 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?

@thomaseizinger
Copy link
Contributor Author

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 :. Something like:

Failed to deserialize long_offer event: invalid type: map, expected unit at line 1 column 0

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 (`#`)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thomaseizinger
Copy link
Contributor Author

bors r+

@bors bors bot merged commit 69e3ff8 into master Mar 16, 2022
@bors bors bot deleted the chore/print-entire-reason-for-restart branch March 16, 2022 23:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants