Skip to content

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

Closed
@JohnTitor

Description

@JohnTitor
Member

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.

Activity

added
O-windowsOperating system: Windows
C-bugCategory: This is a bug.
T-libsRelevant to the library team, which will review and decide on the PR/issue.
A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`
on Nov 16, 2021
added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Nov 16, 2021
ChrisDenton

ChrisDenton commented on Nov 16, 2021

@ChrisDenton
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

JohnTitor commented on Nov 16, 2021

@JohnTitor
MemberAuthor

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

added
E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.
and removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Nov 17, 2021
nbdd0121

nbdd0121 commented on Nov 17, 2021

@nbdd0121
Contributor

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

m-ou-se

m-ou-se commented on Nov 17, 2021

@m-ou-se
Member

Oh oops.

removed
E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.
on Nov 17, 2021

9 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`C-bugCategory: This is a bug.O-windowsOperating system: WindowsP-mediumMedium priorityT-libsRelevant to the library team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      Participants

      @m-ou-se@nbdd0121@ChrisDenton@JohnTitor@rustbot

      Issue actions

        windows: An empty path returns os error 123 instead of os error 3 with recent nightly · Issue #90940 · rust-lang/rust