aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/exec/exec.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2011-11-01 21:49:44 -0400
committerRuss Cox <rsc@golang.org>2011-11-01 21:49:44 -0400
commit451a1fa46d0449dc6982b38ba51cf94ebc750eca (patch)
treefb5307ac50ea9c4fe26fe7c7b306fb72aae699e7 /src/pkg/exec/exec.go
parentc93b6a1756be708ba2d6c8c91c4dabdbbd653cbe (diff)
downloadgo-451a1fa46d0449dc6982b38ba51cf94ebc750eca.tar.xz
exec: introduce ExitError
The existing code uses *os.Waitmsg as an os.Error, but *os.Waitmsg is really just a stringer. Introduce an explicit error type for the real error. Not to be submitted until just before error goes in; the gofix for error updates type assertions err.(*os.Waitmsg) to err.(*exec.ExitError) The seemingly redundant String method will become an Error method when error goes in, and will no longer be redundant. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5331044
Diffstat (limited to 'src/pkg/exec/exec.go')
-rw-r--r--src/pkg/exec/exec.go15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/pkg/exec/exec.go b/src/pkg/exec/exec.go
index aaad50846e..3b818c2f65 100644
--- a/src/pkg/exec/exec.go
+++ b/src/pkg/exec/exec.go
@@ -203,7 +203,7 @@ func (c *Cmd) writerDescriptor(w io.Writer) (f *os.File, err os.Error) {
// status.
//
// If the command fails to run or doesn't complete successfully, the
-// error is of type *os.Waitmsg. Other error types may be
+// error is of type *ExitError. Other error types may be
// returned for I/O problems.
func (c *Cmd) Run() os.Error {
if err := c.Start(); err != nil {
@@ -256,6 +256,15 @@ func (c *Cmd) Start() os.Error {
return nil
}
+// An ExitError reports an unsuccessful exit by a command.
+type ExitError struct {
+ *os.Waitmsg
+}
+
+func (e *ExitError) String() string {
+ return e.Waitmsg.String()
+}
+
// Wait waits for the command to exit.
// It must have been started by Start.
//
@@ -264,7 +273,7 @@ func (c *Cmd) Start() os.Error {
// status.
//
// If the command fails to run or doesn't complete successfully, the
-// error is of type *os.Waitmsg. Other error types may be
+// error is of type *ExitError. Other error types may be
// returned for I/O problems.
func (c *Cmd) Wait() os.Error {
if c.Process == nil {
@@ -290,7 +299,7 @@ func (c *Cmd) Wait() os.Error {
if err != nil {
return err
} else if !msg.Exited() || msg.ExitStatus() != 0 {
- return msg
+ return &ExitError{msg}
}
return copyError