Skip to content

Commit 84bfe72

Browse files
committed
update error handling
- `error.ParseError` was unused - `error.Canceled` needs to be returned to handle cancellation
1 parent 2442435 commit 84bfe72

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

known-folders.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ pub const KnownFolder = enum {
108108
executable_dir,
109109
};
110110

111-
// Explicitly define possible errors to make it clearer what callers need to handle
112-
pub const Error = error{ ParseError, OutOfMemory };
111+
/// Most errors will not be reported here but instead cause null to be returned.
112+
pub const Error = std.mem.Allocator.Error || std.Io.Cancelable;
113113

114114
pub const KnownFolderConfig = struct {
115115
xdg_force_default: bool = false,
@@ -152,7 +152,7 @@ fn getPathInner(
152152
if (folder == .executable_dir) {
153153
if (builtin.os.tag == .wasi) return null;
154154
return std.process.executableDirPathAlloc(io, allocator) catch |err| switch (err) {
155-
error.OutOfMemory => return error.OutOfMemory,
155+
error.OutOfMemory, error.Canceled => |e| return e,
156156
else => null,
157157
};
158158
}
@@ -251,7 +251,7 @@ fn getPathXdg(
251251
break :fallback;
252252

253253
const env = xdgUserDirLookup(System, system, io, allocator, folder_spec.env.name) catch |err| switch (err) {
254-
error.OutOfMemory => return error.OutOfMemory,
254+
error.OutOfMemory, error.Canceled => |e| return e,
255255
else => break :fallback,
256256
} orelse break :fallback;
257257

@@ -382,7 +382,7 @@ const TestingSystem = struct {
382382
const UserDirLookupError =
383383
std.mem.Allocator.Error ||
384384
std.Io.File.OpenError ||
385-
std.posix.ReadError;
385+
std.Io.File.Reader.Error;
386386

387387
const xdg_user_dir_lookup_line_buffer_size: usize = 511;
388388

@@ -537,7 +537,7 @@ const LineIterator = struct {
537537
};
538538
}
539539

540-
fn next(it: *LineIterator, buffer: []u8) std.posix.ReadError!?[:'\n']const u8 {
540+
fn next(it: *LineIterator, buffer: []u8) std.Io.File.Reader.Error!?[:'\n']const u8 {
541541
if (!it.keep_reading) return null;
542542

543543
const reader = &it.file_reader.interface;

0 commit comments

Comments
 (0)