Skip to content

tar: print the tar: prefix once in error messages - #414

Open
jayhemnani9910 wants to merge 2 commits into
uutils:mainfrom
jayhemnani9910:error-prefix-once
Open

jayhemnani9910 wants to merge 2 commits into
uutils:mainfrom
jayhemnani9910:error-prefix-once

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

Every fatal error is printed with the prefix twice:

$ tar -tf nonexistent.tar
tar: tar: nonexistent.tar: Cannot open: No such file or directory
$ tar -cf /nonexistent-dir/x.tar .
tar: tar: Cannot create archive '/nonexistent-dir/x.tar': No such file or directory (os error 2)

GNU tar 1.35 prints tar: nonexistent.tar: Cannot open: No such file or directory. The same happens with the latest-commit release binary.

The TarError messages carried their own tar: , and uucore adds the utility name again when uumain returns the error. The messages no longer include it. report_recoverable and finish_after_previous_errors print the error themselves, so they now add uucore::util_name(), which keeps the recoverable messages (tar: ../x: Member name contains '..') as they were when the binary is called tar.

Tests: a new test_error_message_has_one_prefix fails on main. Three tests in src/uu/tar/tests/test_errors.rs checked the Display text with the tar: included; they now check it without. cargo test --workspace passes (112), cargo fmt --check and cargo clippy --all-targets -- -D warnings are clean.

Not changed: the Removing leading ... from member names warning in create.rs still writes tar: itself.

Copilot AI balanced review requested due to automatic review settings October 23, 2026 06:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@codspeed

codspeed Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 4 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 7 untouched benchmarks


Comparing jayhemnani9910:error-prefix-once (5586a94) with main (b453849)

Open in CodSpeed

@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.17%. Comparing base (791ae26) to head (5586a94).
⚠️ Report is 100 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #414      +/-   ##
==========================================
+ Coverage   96.84%   98.17%   +1.32%     
==========================================
  Files          11       15       +4     
  Lines        1492     1971     +479     
  Branches       29       39      +10     
==========================================
+ Hits         1445     1935     +490     
+ Misses         46       35      -11     
  Partials        1        1              
Flag Coverage Δ
macos_latest 98.17% <100.00%> (+1.32%) ⬆️
ubuntu_latest 98.17% <100.00%> (+1.32%) ⬆️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/uu/tar/src/errors.rs Outdated
/// tells these errors apart from fatal ones.
pub fn finish_after_previous_errors() -> UResult<()> {
writeln!(io::stderr(), "{}", TarError::PreviousErrors).map_err(TarError::Io)?;
writeln!(

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.

could be report_recoverable(&TarError::PreviousErrors)?; no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, done in 5586a94.

Comment thread tests/by-util/test_tar.rs Outdated
}

#[test]
fn test_error_message_has_one_prefix() {

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.

could you please do that in test_extract_nonexistent_archive instead?
something like .stderr_contains(": nonexistent.tar: Cannot open") plus stderr_does_not_contain("tar: tar:"), no unwrap needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved into test_extract_nonexistent_archive in 5586a94. I check stderr_does_not_contain(": tar: ") rather than "tar: tar:": the test binary is tarapp, so main prints tarapp: tar: nonexistent.tar: ... and "tar: tar:" passes there. With ": tar: " the test fails on main and passes here.

Copilot AI balanced review requested due to automatic review settings October 25, 2026 07:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

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.

3 participants