-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathcommand_error.go
49 lines (41 loc) · 923 Bytes
/
command_error.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
package main
import (
"errors"
"fmt"
"strings"
)
type commandError struct {
scd shellCommandDefinition
stderr string
err error
}
func newCommandError(command shellCommandDefinition, stderr string, err error) *commandError {
return &commandError{
scd: command,
stderr: stderr,
err: err,
}
}
func (c *commandError) Error() string {
return c.err.Error()
}
func (c *commandError) Unwrap() error {
return c.err
}
func (c *commandError) Commandline() string {
args := ""
argsList := c.scd.publicArgs
if len(argsList) > 0 {
args = fmt.Sprintf(" \"%s\"", strings.Join(argsList, "\" \""))
}
return fmt.Sprintf("\"%s\"%s", c.scd.command, args)
}
func (c *commandError) Stderr() string {
return c.stderr
}
func (c *commandError) ExitCode() (int, error) {
if exitError, ok := asExitError(c.err); ok {
return exitError.ExitCode(), nil
}
return 0, errors.New("exit code not available")
}