Skip to content

Commit ce74e68

Browse files
committed
Use std.error_set to define SelfExePathError
Instead of redefining the error set from scratch just to exclude a few errors, we can define the error set in terms of existing explicit error sets.
1 parent db79978 commit ce74e68

File tree

1 file changed

+8
-38
lines changed

1 file changed

+8
-38
lines changed

lib/std/fs.zig

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -503,44 +503,14 @@ pub fn openSelfExe(flags: File.OpenFlags) OpenSelfExeError!File {
503503
return openFileAbsoluteZ(buf[0..self_exe_path.len :0].ptr, flags);
504504
}
505505

506-
// This is os.ReadLinkError || os.RealPathError with impossible errors excluded
507-
pub const SelfExePathError = error{
508-
FileNotFound,
509-
AccessDenied,
510-
NameTooLong,
511-
NotSupported,
512-
NotDir,
513-
SymLinkLoop,
514-
InputOutput,
515-
FileTooBig,
516-
IsDir,
517-
ProcessFdQuotaExceeded,
518-
SystemFdQuotaExceeded,
519-
NoDevice,
520-
SystemResources,
521-
NoSpaceLeft,
522-
FileSystem,
523-
BadPathName,
524-
DeviceBusy,
525-
SharingViolation,
526-
PipeBusy,
527-
NotLink,
528-
PathAlreadyExists,
529-
530-
/// On Windows, `\\server` or `\\server\share` was not found.
531-
NetworkNotFound,
532-
533-
/// On Windows, antivirus software is enabled by default. It can be
534-
/// disabled, but Windows Update sometimes ignores the user's preference
535-
/// and re-enables it. When enabled, antivirus software on Windows
536-
/// intercepts file system operations and makes them significantly slower
537-
/// in addition to possibly failing with this error code.
538-
AntivirusInterference,
539-
540-
/// On Windows, the volume does not contain a recognized file system. File
541-
/// system drivers might not be loaded, or the volume may be corrupt.
542-
UnrecognizedVolume,
543-
} || os.SysCtlError;
506+
pub const SelfExePathError = std.error_set.ExcludingAssertAllContained(
507+
os.ReadLinkError || os.RealPathError || os.SysCtlError,
508+
error{
509+
UnsupportedReparsePointType, // Windows-only readlink error; readlink is not called in the Windows implementation
510+
InvalidUtf8, // WASI-only error; selfExePath is not supported on WASI
511+
InvalidWtf8, // selfExePath only converts from WTF-16 -> WTF-8 which cannot fail
512+
},
513+
);
544514

545515
/// `selfExePath` except allocates the result on the heap.
546516
/// Caller owns returned memory.

0 commit comments

Comments
 (0)