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

windows: An empty path returns os error 123 instead of os error 3 with recent nightly #90940

Closed
JohnTitor opened this issue Nov 16, 2021 · 4 comments · Fixed by #90942
Closed
Labels
A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` C-bug Category: This is a bug. O-windows Operating system: Windows P-medium Medium priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Milestone

Comments

@JohnTitor
Copy link
Member

JohnTitor commented Nov 16, 2021

I tried this code:

fn main() {
    let path = std::path::Path::new("");
    if let Err(err) = path.canonicalize() {
        println!("{}", err);
        // println!("{:?}", err.kind());
    }
}

I expected to see this happen: canonicalize() returns os error 3 (ERROR_PATH_NOT_FOUND)

Instead, this happened: it returns os error 123 (ERROR_INVALID_NAME)

This is problematic as std::io::ErrorKind doesn't become NotFound but Uncategorized, which isn't useful for most users. Other platforms like Linux return NotFound so the former behavior should be correct here.

Meta

rustc --version --verbose:

rustc 1.58.0-nightly (e249ce6b2 2021-10-30)
binary: rustc
commit-hash: e249ce6b2345587d6e11052779c86adbad626dff
commit-date: 2021-10-30
host: x86_64-pc-windows-msvc
release: 1.58.0-nightly
LLVM version: 13.0.0

The issue doesn't happen on rustc 1.58.0-nightly (e99963c55 2021-10-29), I think the regression was introduced by #89174.

@JohnTitor JohnTitor added O-windows Operating system: Windows regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue. A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` labels Nov 16, 2021
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Nov 16, 2021
@ChrisDenton
Copy link
Member

Thanks for finding and fixing that! I do think that ERROR_INVALID_NAME should be mapped to an ErrorKind. It means "The filename, directory name, or volume label syntax is incorrect". So a syntax error basically.

But I don't think that should block your current PR.

@JohnTitor
Copy link
Member Author

JohnTitor commented Nov 16, 2021

Sounds good, maybe it should be InvalidInput? (EDIT: Opened #90955)

@m-ou-se m-ou-se added E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Nov 17, 2021
@nbdd0121
Copy link
Contributor

@m-ou-se is it intentional that E-medium is added instead of P-medium?

@m-ou-se
Copy link
Member

m-ou-se commented Nov 17, 2021

Oh oops.

@m-ou-se m-ou-se added P-medium Medium priority and removed E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. labels Nov 17, 2021
@m-ou-se m-ou-se added this to the 1.58.0 milestone Nov 17, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 18, 2021
windows: Return the "Not Found" error when a path is empty

Fixes rust-lang#90940
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 18, 2021
windows: Return the "Not Found" error when a path is empty

Fixes rust-lang#90940
@bors bors closed this as completed in f62984f Nov 19, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 11, 2022
…nput, r=m-ou-se

Rename `FilenameTooLong` to `InvalidFilename` and also use it for Windows' `ERROR_INVALID_NAME`

Address rust-lang#90940 (comment)
`ERROR_INVALID_NAME` (i.e. "The filename, directory name, or volume label syntax is incorrect") happens if we pass an invalid filename, directory name, or label syntax, so mapping as `InvalidInput` is reasonable to me.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 11, 2022
…nput, r=m-ou-se

Rename `FilenameTooLong` to `InvalidFilename` and also use it for Windows' `ERROR_INVALID_NAME`

Address rust-lang#90940 (comment)
`ERROR_INVALID_NAME` (i.e. "The filename, directory name, or volume label syntax is incorrect") happens if we pass an invalid filename, directory name, or label syntax, so mapping as `InvalidInput` is reasonable to me.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 11, 2022
…nput, r=m-ou-se

Rename `FilenameTooLong` to `InvalidFilename` and also use it for Windows' `ERROR_INVALID_NAME`

Address rust-lang#90940 (comment)
`ERROR_INVALID_NAME` (i.e. "The filename, directory name, or volume label syntax is incorrect") happens if we pass an invalid filename, directory name, or label syntax, so mapping as `InvalidInput` is reasonable to me.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` C-bug Category: This is a bug. O-windows Operating system: Windows P-medium Medium priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants