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

Feature: track caller #287

Closed
wants to merge 3 commits into from
Closed

Conversation

har7an
Copy link

@har7an har7an commented Dec 6, 2022

This PR tries to add caller tracking with a new feature, "track_caller". This will allow, if set, to track the caller of any call of context or with_context and print it in the errors output.

Current State

MWE:

use anyhow::Result;
use anyhow::Context;

fn main() -> Result<()> {
    None
        .context("A")
        .context("B")
        .with_context(|| format!("{}", "C"))?
}

Output:

Error: C
  at src/main.rs:8


Caused by:
    0: B
    1: A

TODO

The PR isn't complete yet. It's still missing the ability to access the stored caller Location information in the call to fmt::debug. However, I do not know how to turn a &dyn Error into a Ref<ImplError> for this purpose. Does anyone have advice for me, please?

Related to #139

to track caller locations for `context` and `with_context` and display
them along with the errors if enabled.
if the "track_caller" feature is set. Store it inside the `ErrorImpl` so
it can be accessed as needed, similar to how backtraces are implemented.
Copy link
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I have already been working on this (65290ed). It doesn't look like there is anything in this PR that isn't already done there, and since it sounds like you are stuck on the debug implementation, I'll close this in favor of continuing my own commit.

@dtolnay dtolnay closed this Dec 6, 2022
@rikvdkleij
Copy link

@dtolnay Any idea when your location feature will be released?

@Equim-chan
Copy link

@dtolnay The location branch seems to have been deleted. Is this feature still in plan?

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.

None yet

4 participants