Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: print source for error to make it easier to debug #2297

Conversation

PureWhiteWu
Copy link

Currently when encounter errors, the Error type only prints a message like this:

error sending request for url (http://xxx)

It doesn't print the underlying cause, so it's hard to debug.

This PR also prints the inner source which makes it easier to debug, such as:

error sending request for url (http://xxx): operation timed out

@seanmonstar
Copy link
Owner

This was purposefully removed in 0.12, since Rust best practices recommend not doing that. Instead, some reporter that crawls the sources should be used instead.

@PureWhiteWu PureWhiteWu deleted the feat/print_source_for_error branch May 31, 2024 12:21
@PureWhiteWu PureWhiteWu restored the feat/print_source_for_error branch May 31, 2024 12:31
@PureWhiteWu
Copy link
Author

PureWhiteWu commented May 31, 2024

Hi @seanmonstar , thanks very much for your reply!

Rust best practices recommend not doing that

Could you please give me an reference link? I didn't know about this.

Instead, some reporter that crawls the sources should be used instead.

In my case, I'm defining my own error type using thiserror like this:

#[derive(thiserror::Error)]
pub enum Error {
    #[error("reqwest error: {0}")]
    ReqwestError(#[from] reqwest::Error),
}

In this case, I don't know how to add something like Report to print the inner source.

Since thiserror is a famous crate to handle error and the Report is still nightly only, I still think maybe we should add this back now? Maybe we can remove it in the future when the Report is stabilized?

@seanmonstar
Copy link
Owner

Could you please give me an reference link?

rust-lang/project-error-handling#27 (comment)

You wouldn't use a reporter inside the type you've derived with thiserror. Rather, the reporter is to be used by the application layer, whatever is "reporting" the error in plain text. Things like anyhow and eyre already provide reporters.

@PureWhiteWu
Copy link
Author

Thanks very much!

@PureWhiteWu PureWhiteWu deleted the feat/print_source_for_error branch May 31, 2024 12:52
@PureWhiteWu
Copy link
Author

I've commented in that issue rust-lang/project-error-handling#27 (comment), and I sincerely look forward to hearing your advice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants