Log and print original error for start
Currently `start` will hide some errors and throw a consolidated error, which will make it hard to debug because developer can't find the original error. This commit allow daemon to log original errors first. Signed-off-by: Zhang Wei <zhangwei555@huawei.com> Upstream-commit: b4740e3021a39a502ffc82f0f70e9b7ed2f0875f Component: engine
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
@ -315,18 +316,18 @@ func reportError(stderr io.Writer, name string, str string, withHelp bool) {
|
||||
fmt.Fprintf(stderr, "%s: %s.\n", os.Args[0], str)
|
||||
}
|
||||
|
||||
// if container start fails with 'command not found' error, return 127
|
||||
// if container start fails with 'command cannot be invoked' error, return 126
|
||||
// if container start fails with 'not found'/'no such' error, return 127
|
||||
// if container start fails with 'permission denied' error, return 126
|
||||
// return 125 for generic docker daemon failures
|
||||
func runStartContainerErr(err error) error {
|
||||
trimmedErr := strings.TrimPrefix(err.Error(), "Error response from daemon: ")
|
||||
statusError := cli.StatusError{StatusCode: 125}
|
||||
if strings.HasPrefix(trimmedErr, "Container command") {
|
||||
if strings.Contains(trimmedErr, errCmdNotFound) {
|
||||
statusError = cli.StatusError{StatusCode: 127}
|
||||
} else if strings.Contains(trimmedErr, errCmdCouldNotBeInvoked) {
|
||||
statusError = cli.StatusError{StatusCode: 126}
|
||||
}
|
||||
if strings.Contains(trimmedErr, "executable file not found") ||
|
||||
strings.Contains(trimmedErr, "no such file or directory") ||
|
||||
strings.Contains(trimmedErr, "system cannot find the file specified") {
|
||||
statusError = cli.StatusError{StatusCode: 127}
|
||||
} else if strings.Contains(trimmedErr, syscall.EACCES.Error()) {
|
||||
statusError = cli.StatusError{StatusCode: 126}
|
||||
}
|
||||
|
||||
return statusError
|
||||
|
||||
Reference in New Issue
Block a user