Skip to content

Fix #[track_caller] for .success(), .failure(), and more#289

Open
marcospb19 wants to merge 1 commit intoassert-rs:masterfrom
marcospb19:track_caller
Open

Fix #[track_caller] for .success(), .failure(), and more#289
marcospb19 wants to merge 1 commit intoassert-rs:masterfrom
marcospb19:track_caller

Conversation

@marcospb19
Copy link
Copy Markdown

In ouch I've long had the problem of .success() and .failure() giving me a panic that happened at $HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5.

use assert_cmd::Command;

fn main() {
    Command::new("false")
        .assert()
        .success();
}

Running this you get:

thread 'main' (3911719) panicked at /home/marcospb19/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5:
Unexpected failure.

So in this PR I fix the function wrapping that prevented #[track_caller] from working, here is what it looks like now:

thread 'main' (3914770) panicked at src/main.rs:6:10:
Unexpected failure.

I also added a bunch of #[track_caller] at places where there is a panic path, let me know if you think that's excessive.

Comment thread src/assert.rs
Comment thread src/cargo.rs
/// # Panic
///
/// Panicks if no binary is found
#[track_caller]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems uncommon enough and with enough context that it might not be needed

@epage
Copy link
Copy Markdown
Contributor

epage commented Apr 29, 2026

Yeah, that is really annoying situation with combinators.

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