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

Improve error handling in approval voting block import #5283

Merged

Conversation

koute
Copy link
Contributor

@koute koute commented Apr 8, 2022

We already print out a warning here, so we might as well also print out the actual error message instead of just ignoring it.

(Motivation: I was investigating this issue which triggers this warning. I'd like to have the WASM stack trace printed out in the error message when something panics; we can't do that if the errors are ignored and never printed out the first place.)

@koute koute added A0-please_review Pull request needs code review. J0-enhancement An additional feature request. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit. labels Apr 8, 2022
Copy link
Contributor

@wigy-opensource-developer wigy-opensource-developer left a comment

Choose a reason for hiding this comment

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

Nice.

@wigy-opensource-developer wigy-opensource-developer dismissed their stale review April 8, 2022 08:23

Just noticed I was not asked to review.

@eskimor eskimor merged commit b216f1f into paritytech:master Apr 8, 2022
RuntimeError(RuntimeApiError),

#[error("future cancalled while requesting {0}")]
FutureCancelled(&'static str, futures::channel::oneshot::Canceled),
Copy link
Contributor

Choose a reason for hiding this comment

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

Canceled should be annotated with #[source]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I missed that.

That said, in this case in practice since Canceled is a ZST and doesn't actually carry any information it shouldn't make any practical difference.

I'm happy to make a followup PR and add this in though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just a nit :)

/// The runtime API cannot be executed due to a
#[error("The runtime API '{runtime_api_name}' cannot be executed")]
/// The runtime API cannot be executed due to a runtime error.
#[error("The runtime API '{runtime_api_name}' cannot be executed: {source}")]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: source will be printed twice now in the backtrace, once as part of the backtrace and as part of the error message itself iirc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you know how you'd have to print it out to actually get it printed out twice?

Because when printed out through a normal Display trait:

    #[test]
    fn test_foobar() {
        #[derive(thiserror::Error, Debug)]
        #[error("source")]
        struct Source;
        let err = RuntimeApiError::Execution { runtime_api_name: "Test", source: Arc::new(Source) };
        panic!("{}", err);
    }

it's printed out like this:

thread 'import::tests::test_foobar' panicked at 'The runtime API 'Test' cannot be executed: source', node/core/approval-voting/src/import.rs:1351:9

And we usually print out errors through Display (or Debug).

@drahnr
Copy link
Contributor

drahnr commented Apr 8, 2022

There are two ways to get the full error chain:

while let Some(err) = err.source() {
eprintln!("caused by: {}");
}

or using a predfined formatter, i.e. eyre::Report https://docs.rs/eyre/0.6.8/eyre/struct.Report.html

eprintln!("{:?}", Report::from(err));

which also shows the backtrace if captured :)

@koute
Copy link
Contributor Author

koute commented Apr 8, 2022

There are two ways to get the full error chain:

while let Some(err) = err.source() {
eprintln!("caused by: {}");
}

or using a predfined formatter, i.e. eyre::Report https://docs.rs/eyre/0.6.8/eyre/struct.Report.html

eprintln!("{:?}", Report::from(err));

which also shows the backtrace if captured :)

Okay, I see! I was asking because I've never seen this in our codebase, and a quick grep confirms that neither the .source() nor Report::from are called in both substrate or polkadot even a single time (if I'm grepping this right, which I might not).

So in theory you're right, but yeah, it practice it doesn't seem to matter; at this point this train has already left the station a long time ago, and it'd take a huge effort to rework the whole codebase to use any other way of printing out errors. We can't even guarantee that we use Display instead of Debug everywhere; enforcing an alternative backtrace-y way of printing errors would be a nightmare without some sort of an automatic clippy lint to actually make sure the errors are not printed any other way.

@drahnr
Copy link
Contributor

drahnr commented Apr 8, 2022

We do, every error that bubbles up to the main fn will be printed using eyre (wrapped in color_eyre) - but that's only fatal errors make it that far up.

So in theory you're right, but yeah, it practice it doesn't seem to matter; at this point this train has already left the station a long time ago, and it'd take a huge effort to rework the whole codebase to use any other way of printing out errors. We can't even guarantee that we use Display instead of Debug everywhere; enforcing an alternative backtrace-y way of printing errors would be a nightmare without some sort of an automatic clippy lint to actually make sure the errors are not printed any other way.

Using a helper fn and using that consistently should suffice, I think there are only a few dozend of those and it's only relevant when being the end of the line print for this error with no further actions being done upon. I am mostly talking about polkadot / subsystems here.

ordian added a commit that referenced this pull request Apr 13, 2022
* master: (62 commits)
  Bump tracing from 0.1.32 to 0.1.33 (#5299)
  Add staging runtime api (#5048)
  CI: rename ambiguous jobs (#5313)
  Prepare for rust 1.60 (#5282)
  Bump proc-macro2 from 1.0.36 to 1.0.37 (#5265)
  Fixes the dead lock when any of the channels get at capacity. (#5297)
  Bump syn from 1.0.90 to 1.0.91 (#5273)
  create .github/workflows/pr-custom-review.yml (#5280)
  [ci] fix pallet benchmark script (#5247) (#5292)
  bump spec_version to 9190 (#5291)
  bump version to 0.9.19 (#5290)
  Session is actually ancient not unknown. (#5286)
  [ci] point benchmark script to sub-commands (#5247) (#5289)
  Remove Travis CI (#5287)
  Improve error handling in approval voting block import (#5283)
  fix .github/pr-custom-review.yml (#5279)
  Co #11164: Sub-commands for `benchmark` (#5247)
  Bump clap from 3.1.6 to 3.1.8 (#5240)
  Custom Slots Migration for Fund Index Change (#5227)
  create pr-custom-review.yml (#5253)
  ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit. J0-enhancement An additional feature request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants