Skip to content

Commit

Permalink
Use std.error_set to define SelfExePathError
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
squeek502 committed Feb 27, 2024
1 parent 6c0f47f commit 14b47f9
Showing 1 changed file with 8 additions and 39 deletions.
47 changes: 8 additions & 39 deletions lib/std/fs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -503,45 +503,14 @@ pub fn openSelfExe(flags: File.OpenFlags) OpenSelfExeError!File {
return openFileAbsoluteZ(buf[0..self_exe_path.len :0].ptr, flags);
}

// This is os.ReadLinkError || os.RealPathError with impossible errors excluded
pub const SelfExePathError = error{
FileNotFound,
AccessDenied,
NameTooLong,
NotSupported,
NotDir,
SymLinkLoop,
InputOutput,
FileTooBig,
IsDir,
ProcessFdQuotaExceeded,
SystemFdQuotaExceeded,
NoDevice,
SystemResources,
NoSpaceLeft,
FileSystem,
BadPathName,
DeviceBusy,
SharingViolation,
PipeBusy,
NotLink,
PathAlreadyExists,
InvalidHandle,

/// On Windows, `\\server` or `\\server\share` was not found.
NetworkNotFound,

/// On Windows, antivirus software is enabled by default. It can be
/// disabled, but Windows Update sometimes ignores the user's preference
/// and re-enables it. When enabled, antivirus software on Windows
/// intercepts file system operations and makes them significantly slower
/// in addition to possibly failing with this error code.
AntivirusInterference,

/// On Windows, the volume does not contain a recognized file system. File
/// system drivers might not be loaded, or the volume may be corrupt.
UnrecognizedVolume,
} || os.SysCtlError;
pub const SelfExePathError = std.error_set.ExcludingAssertAllContained(
os.ReadLinkError || os.RealPathError || os.SysCtlError,
error{
UnsupportedReparsePointType, // Windows-only readlink error; readlink is not called in the Windows implementation
InvalidUtf8, // WASI-only error; selfExePath is not supported on WASI
InvalidWtf8, // selfExePath only converts from WTF-16 -> WTF-8 which cannot fail
},
);

/// `selfExePath` except allocates the result on the heap.
/// Caller owns returned memory.
Expand Down

0 comments on commit 14b47f9

Please sign in to comment.