Skip to content

Commit 32f602a

Browse files
authored
std.os.windows: handle OBJECT_NAME_INVALID in OpenFile (#19288)
It's been seen on Windows 11 (22H2) Build 22621.3155 that NtCreateFile will return the OBJECT_NAME_INVALID error code with certain path names. The path name we saw this with started with `C:Users` (rather than `C:\Users`) and also contained a `$` character. This PR updates our OpenFile wrapper to propagate this error code as `error.BadPathName` instead of making it `unreachable`. see marler8997/zigup#114 (comment)
1 parent 2008b14 commit 32f602a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/std/os/windows.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub const OpenError = error{
4242
WouldBlock,
4343
NetworkNotFound,
4444
AntivirusInterference,
45+
BadPathName,
4546
};
4647

4748
pub const OpenFileOptions = struct {
@@ -120,7 +121,7 @@ pub fn OpenFile(sub_path_w: []const u16, options: OpenFileOptions) OpenError!HAN
120121
);
121122
switch (rc) {
122123
.SUCCESS => return result,
123-
.OBJECT_NAME_INVALID => unreachable,
124+
.OBJECT_NAME_INVALID => return error.BadPathName,
124125
.OBJECT_NAME_NOT_FOUND => return error.FileNotFound,
125126
.OBJECT_PATH_NOT_FOUND => return error.FileNotFound,
126127
.BAD_NETWORK_PATH => return error.NetworkNotFound, // \\server was not found

0 commit comments

Comments
 (0)