From 0243a5b8bed75dcb2c3eca2be2b3bcdb0f311eb1 Mon Sep 17 00:00:00 2001 From: ZauberNerd Date: Fri, 4 Mar 2022 15:31:31 +0000 Subject: [PATCH] src/os: add stubs for exec.ExitError and ProcessState.ExitCode This commit adds stubs for the `ExitError` struct of the `exec` package and `ProcessState.ExitCode()` of the `os` package. Since the `os/exec` is listed as unsupported, stubbing these methods and structs should be enough to get programs that use these to compile. --- src/os/exec.go | 6 ++++++ src/os/exec/exec.go | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/os/exec/exec.go diff --git a/src/os/exec.go b/src/os/exec.go index 067be0de..903daf48 100644 --- a/src/os/exec.go +++ b/src/os/exec.go @@ -34,6 +34,12 @@ func (p *ProcessState) Success() bool { return false // TODO } +// ExitCode returns the exit code of the exited process, or -1 +// if the process hasn't exited or was terminated by a signal. +func (p *ProcessState) ExitCode() int { + return -1 // TODO +} + type Process struct { Pid int } diff --git a/src/os/exec/exec.go b/src/os/exec/exec.go new file mode 100644 index 00000000..afb44570 --- /dev/null +++ b/src/os/exec/exec.go @@ -0,0 +1,24 @@ +package exec + +import "os" + +// An ExitError reports an unsuccessful exit by a command. +type ExitError struct { + *os.ProcessState + + // Stderr holds a subset of the standard error output from the + // Cmd.Output method if standard error was not otherwise being + // collected. + // + // If the error output is long, Stderr may contain only a prefix + // and suffix of the output, with the middle replaced with + // text about the number of omitted bytes. + // + // Stderr is provided for debugging, for inclusion in error messages. + // Users with other needs should redirect Cmd.Stderr as needed. + Stderr []byte +} + +func (e *ExitError) Error() string { + return e.ProcessState.String() +}