summaryrefslogtreecommitdiff
path: root/cmd/podman/errors.go
blob: ae9e73e62fe055fa6e37efd90e252654e9d82586 (plain)
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
// +build !remoteclient

package main

import (
	"fmt"
	"os"
	"os/exec"
	"syscall"

	"github.com/containers/libpod/libpod/define"
	"github.com/pkg/errors"
	"github.com/sirupsen/logrus"
)

func outputError(err error) {
	if MainGlobalOpts.LogLevel == "debug" {
		logrus.Errorf(err.Error())
	} else {
		ee, ok := err.(*exec.ExitError)
		if ok {
			if status, ok := ee.Sys().(syscall.WaitStatus); ok {
				exitCode = status.ExitStatus()
			}
		}
		fmt.Fprintln(os.Stderr, "Error:", err.Error())
	}
}

func setExitCode(err error) int {
	cause := errors.Cause(err)
	switch cause {
	case define.ErrNoSuchCtr:
		return 1
	case define.ErrCtrStateInvalid:
		return 2
	}
	return exitCode
}