github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/cmd/podman/errors.go (about)

     1  // +build !remoteclient
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"os"
     8  	"os/exec"
     9  	"syscall"
    10  
    11  	"github.com/containers/libpod/libpod/define"
    12  	"github.com/pkg/errors"
    13  	"github.com/sirupsen/logrus"
    14  )
    15  
    16  func outputError(err error) {
    17  	if MainGlobalOpts.LogLevel == "debug" {
    18  		logrus.Errorf(err.Error())
    19  	} else {
    20  		ee, ok := err.(*exec.ExitError)
    21  		if ok {
    22  			if status, ok := ee.Sys().(syscall.WaitStatus); ok {
    23  				exitCode = status.ExitStatus()
    24  			}
    25  		}
    26  		fmt.Fprintln(os.Stderr, "Error:", err.Error())
    27  	}
    28  }
    29  
    30  func setExitCode(err error) int {
    31  	cause := errors.Cause(err)
    32  	switch cause {
    33  	case define.ErrNoSuchCtr:
    34  		return 1
    35  	case define.ErrCtrStateInvalid:
    36  		return 2
    37  	}
    38  	return exitCode
    39  }