From 0d3feb7f51223e26599ef49764eea7640358ba6d Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Wed, 13 Mar 2024 07:50:00 -0600 Subject: [PATCH] std.os.windows: handle OBJECT_NAME_INVALID in OpenFile 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 https://github.com/marler8997/zigup/issues/114#issuecomment-1994420791 --- lib/std/os/windows.zig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index 51fe924dc37e..5bd71487a212 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -42,6 +42,7 @@ pub const OpenError = error{ WouldBlock, NetworkNotFound, AntivirusInterference, + BadPathName, }; pub const OpenFileOptions = struct { @@ -120,7 +121,7 @@ pub fn OpenFile(sub_path_w: []const u16, options: OpenFileOptions) OpenError!HAN ); switch (rc) { .SUCCESS => return result, - .OBJECT_NAME_INVALID => unreachable, + .OBJECT_NAME_INVALID => return error.BadPathName, .OBJECT_NAME_NOT_FOUND => return error.FileNotFound, .OBJECT_PATH_NOT_FOUND => return error.FileNotFound, .BAD_NETWORK_PATH => return error.NetworkNotFound, // \\server was not found