// 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 {
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.
//
// 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 {
if err != nil {
return err
} else if !msg.Exited() || msg.ExitStatus() != 0 {
- return msg
+ return &ExitError{msg}
}
return copyError
func TestCatGoodAndBadFile(t *testing.T) {
// Testing combined output and error values.
bs, err := helperCommand("cat", "/bogus/file.foo", "exec_test.go").CombinedOutput()
- if _, ok := err.(*os.Waitmsg); !ok {
- t.Errorf("expected Waitmsg from cat combined; got %T: %v", err, err)
+ if _, ok := err.(*ExitError); !ok {
+ t.Errorf("expected *ExitError from cat combined; got %T: %v", err, err)
}
s := string(bs)
sp := strings.SplitN(s, "\n", 2)
func TestExitStatus(t *testing.T) {
// Test that exit values are returned correctly
err := helperCommand("exit", "42").Run()
- if werr, ok := err.(*os.Waitmsg); ok {
+ if werr, ok := err.(*ExitError); ok {
if s, e := werr.String(), "exit status 42"; s != e {
t.Errorf("from exit 42 got exit %q, want %q", s, e)
}
} else {
- t.Fatalf("expected Waitmsg from exit 42; got %T: %v", err, err)
+ t.Fatalf("expected *ExitError from exit 42; got %T: %v", err, err)
}
}