Repository navigation
ls: report invalid file names as "cannot access" instead of an unknown io error - #15699
armadavalor wants to merge 2 commits into
Conversation
…n io error Errors without a dedicated message (e.g. ERROR_INVALID_NAME on Windows for `*` or `<`, or a name that is too long) were printed as "unknown io error" with the Debug form of io::Error. Print them like the other access errors, using the OS message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| new_ucmd!() | ||
| .arg(&name) | ||
| .fails_with_code(2) | ||
| .stderr_contains(format!("ls: cannot access '{name}': ")) |
There was a problem hiding this comment.
on unix, could we check the full message with stderr_is("... File name too long\n")? the prefix check is a bit weak
| .arg(&name) | ||
| .fails_with_code(2) | ||
| .stderr_contains(format!("ls: cannot access '{name}': ")) | ||
| .stderr_does_not_contain("unknown io error") |
There was a problem hiding this comment.
the unknown io error check is redundant with the stderr_contains above, no?
Merging this PR will degrade performance by 3%2 warnings, 1 note
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
Closes #6710
On Windows,
lswith a name that contains*or<, or with a name that is too long, fell into the catch-all error branch and printed the rawio::Errordebug output. Now these errors use the samecannot accessmessage as the other errors, with the OS text and without the(os error N)suffix.Before:
After:
The exit code is still 2.
The fix is in the
IOErrorContextfallback inls.rs. I replacedls-error-unknown-io-errorwithls-error-cannot-accessin en-US and fr-FR. This is not Windows-specific: any other unmapped error now prints like GNU'scannot access ...: <strerror>.Tests (in
tests/by-util/test_ls.rs):test_name_too_long, a 300-character name (runs on all platforms)test_invalid_filename_windows,a*anda<b(Windows only)The tests only check the
ls: cannot access '<name>':prefix, because the OS message is localized on Windows and differs between libcs.🤖 Generated with Claude Code