forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.go
51 lines (44 loc) · 1 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package localcmd
import (
"bytes"
"fmt"
"github.com/openshift/origin/pkg/cmd/util/prefixwriter"
)
// execError is an error that occurred executing a local command
type execError struct {
cmd []string
cause error
stdOut []byte
errOut []byte
}
func newExecError(cmd []string, cause error, stdOut, errOut []byte) error {
return &execError{
cmd: cmd,
cause: cause,
stdOut: stdOut,
errOut: errOut,
}
}
func (e *execError) Error() string {
return fmt.Sprintf("exec error: %v", e.cause)
}
func (e *execError) Cause() error {
return e.cause
}
func (e *execError) Details() string {
out := &bytes.Buffer{}
fmt.Fprintf(out, "Command: %v\n", e.cmd)
if len(e.stdOut) > 0 {
fmt.Fprintf(out, "Standard output:\n")
w := prefixwriter.New(" ", out)
w.Write(bytes.TrimSpace(e.stdOut))
fmt.Fprintf(out, "\n")
}
if len(e.errOut) > 0 {
fmt.Fprintf(out, "Error output:\n")
w := prefixwriter.New(" ", out)
w.Write(bytes.TrimSpace(e.errOut))
fmt.Fprintf(out, "\n")
}
return out.String()
}