mktemp: strip OS error code from permission-denied message - #13815
mktemp: strip OS error code from permission-denied message#13815MsfPablo wants to merge 1 commit into
Conversation
mktemp leaked the raw `Permission denied (os error 13) at path "..."` text from the underlying tempfile crate when creating a temporary file/dir in an unwritable directory, instead of the clean `Permission denied` message used elsewhere in uutils. Route the io::Error through a new MkTempError::Io variant that renders with strip_errno, as maintainer sylvestre suggested in uutils#13720, so the `(os error N)` suffix and the internal `at path ...` detail are dropped. Add a regression test (skipped under root) that asserts the clean message for both the file and directory cases. Closes uutils#13720
|
Both failing lint jobs ( This is in |
|
Could you please write the messages yourself? Llm comments are not helpful |
| /// underlying `tempfile` crate would otherwise embed. | ||
| #[cfg(unix)] | ||
| #[test] | ||
| fn test_permission_denied_clean_message() { |
There was a problem hiding this comment.
| fn test_permission_denied_clean_message() { | |
| fn test_permission_denied() { |
The description should focus on testing the behavior being testing rather than lacking the specific (os error N) suffix (which is obvious).
Merging this PR will degrade performance by 4.91%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | du_max_depth_balanced_tree[(6, 4, 10)] |
63 ms | 66.6 ms | -5.47% |
| ❌ | Simulation | du_summarize_balanced_tree[(5, 4, 10)] |
16.3 ms | 17 ms | -4.35% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing MsfPablo:mktemp-strip-os-error-v2 (dc41de7) with main (a8efa79)
Footnotes
-
46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
|
Hi, it'd be good if the error message is |
|
GNU testsuite comparison: |
Agreed, I don't think stripping the path is an improvement. |
What
Creating a temporary file or directory in an unwritable directory leaked the raw
Permission denied (os error 13) at path "..."text from the underlyingtempfilecrate, instead of the cleanPermission deniedmessage used elsewhere in uutils:Why
tempfilewraps the underlyingio::Errorasio::Error::new(kind, "{<inner display>} at path {path:?}"). That wrapper hasraw_os_error() == None, soUIoError::Displayskips its kind-match normalization branch and printsself.inner.to_string()verbatim — which still contains the(os error 13)suffix and the internalat path "..."detail.Routing the error through a dedicated
MkTempError::Io(std::io::Error)variant rendered withstrip_errno(as @sylvestre suggested in the issue) drops both the(os error N)suffix and the internal path detail, matching howperms.rs(common-write-error) andcsplitrender io errors:Changes
src/uu/mktemp/src/mktemp.rs: addMkTempError::Io(std::io::Error)rendered withstrip_errno, and route the two catch-allErr(e) => Err(e.into())arms inmake_temp_file/make_temp_dirthrough it.tests/by-util/test_mktemp.rs: addtest_permission_denied_clean_message(Unix, skipped under root) asserting the clean message for both the file and directory cases.Closes #13720.
Verification
cargo build --bin coreutils --no-default-features --features mktempcargo test --no-default-features --features mktemp --test tests -- mktemp→ 41 passedcargo fmt --all -- --check→ cleancargo clippy --no-default-features --features mktemp→ cleanAI disclosure
This change was authored with the assistance of Claude (Anthropic). The diagnosis of the
UIoError::Displayfall-through, the fix design (mirroringperms.rs/csplit), the test, and the verification were all produced with AI assistance and reviewed by me.Note on prior claim
I saw that @AnandajithS mentioned working on this in the issue and @Devel08 followed up. No PR appeared after several days, so I went ahead. Happy to close/defer this if a PR from the original claimant is in flight — let me know.