authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-11-25 12:39:57-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-11-25 14:18:55-08:00
logaa5341bf85e2aab566ae235c24f85ddaf09e8aee
treef253058036dfd894f1125fb66c1b41cbe06c3262
parentf4e042a4c3e8e299d273f00b757ec9fce840c3a6

std.process.Child: explicit error set for wait


1 files changed, 10 insertions(+), 13 deletions(-)

lib/std/process/Child.zig+10-13
......@@ -293,19 +293,16 @@ pub fn killPosix(self: *ChildProcess) !Term {
293293 error.ProcessNotFound => return error.AlreadyTerminated,
294294 else => return err,
295295 };
296 try self.waitUnwrapped();
296 self.waitUnwrapped();
297297 return self.term.?;
298298}
299299
300/// Blocks until child process terminates and then cleans up all resources.
301pub fn wait(self: *ChildProcess) !Term {
302 const term = if (native_os == .windows)
303 try self.waitWindows()
304 else
305 try self.waitPosix();
300pub const WaitError = SpawnError || std.os.windows.GetProcessMemoryInfoError;
306301
302/// Blocks until child process terminates and then cleans up all resources.
303pub fn wait(self: *ChildProcess) WaitError!Term {
304 const term = if (native_os == .windows) try self.waitWindows() else self.waitPosix();
307305 self.id = undefined;
308
309306 return term;
310307}
311308
......@@ -408,7 +405,7 @@ pub fn run(args: struct {
408405 };
409406}
410407
411fn waitWindows(self: *ChildProcess) !Term {
408fn waitWindows(self: *ChildProcess) WaitError!Term {
412409 if (self.term) |term| {
413410 self.cleanupStreams();
414411 return term;
......@@ -418,17 +415,17 @@ fn waitWindows(self: *ChildProcess) !Term {
418415 return self.term.?;
419416}
420417
421fn waitPosix(self: *ChildProcess) !Term {
418fn waitPosix(self: *ChildProcess) SpawnError!Term {
422419 if (self.term) |term| {
423420 self.cleanupStreams();
424421 return term;
425422 }
426423
427 try self.waitUnwrapped();
424 self.waitUnwrapped();
428425 return self.term.?;
429426}
430427
431fn waitUnwrappedWindows(self: *ChildProcess) !void {
428fn waitUnwrappedWindows(self: *ChildProcess) WaitError!void {
432429 const result = windows.WaitForSingleObjectEx(self.id, windows.INFINITE, false);
433430
434431 self.term = @as(SpawnError!Term, x: {
......@@ -450,7 +447,7 @@ fn waitUnwrappedWindows(self: *ChildProcess) !void {
450447 return result;
451448}
452449
453fn waitUnwrapped(self: *ChildProcess) !void {
450fn waitUnwrapped(self: *ChildProcess) void {
454451 const res: posix.WaitPidResult = res: {
455452 if (self.request_resource_usage_statistics) {
456453 switch (native_os) {