mirror of https://github.com/containers/conmon.git
runner: stop using pkg/errors
The github.com/pkg/errors is frozen since November 2021, and %w for fmt.Errorf is available since Go 1.13 (September 2019). Switch from pkg/errors to Go native way of wrapping errors. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
parent
475c7de10f
commit
c490967a23
1
go.mod
1
go.mod
|
|
@ -8,7 +8,6 @@ require (
|
|||
github.com/onsi/ginkgo/v2 v2.15.0
|
||||
github.com/onsi/gomega v1.31.1
|
||||
github.com/opencontainers/runtime-tools v0.9.1-0.20230914150019-408c51e934dc
|
||||
github.com/pkg/errors v0.9.1
|
||||
golang.org/x/sys v0.20.0
|
||||
)
|
||||
|
||||
|
|
|
|||
2
go.sum
2
go.sum
|
|
@ -41,8 +41,6 @@ github.com/opencontainers/runtime-spec v1.1.0-rc.3/go.mod h1:jwyrGlmzljRJv/Fgzds
|
|||
github.com/opencontainers/runtime-tools v0.9.1-0.20230914150019-408c51e934dc h1:d2hUh5O6MRBvStV55MQ8we08t42zSTqBbscoQccWmMc=
|
||||
github.com/opencontainers/runtime-tools v0.9.1-0.20230914150019-408c51e934dc/go.mod h1:8tx1helyqhUC65McMm3x7HmOex8lO2/v9zPuxmKHurs=
|
||||
github.com/opencontainers/selinux v1.11.0 h1:+5Zbo97w3Lbmb3PeqQtpmTkMwsW5nRI3YaLpt7tQ7oU=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
package conmon
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrConmonNotStarted = errors.New("conmon instance is not started")
|
||||
)
|
||||
var ErrConmonNotStarted = errors.New("conmon instance is not started")
|
||||
|
||||
type ConmonInstance struct {
|
||||
args []string
|
||||
|
|
@ -99,7 +97,7 @@ func (ci *ConmonInstance) Stderr() (io.Writer, error) {
|
|||
|
||||
func (ci *ConmonInstance) Pid() (int, error) {
|
||||
if ci.pidFile == "" {
|
||||
return -1, errors.Errorf("conmon pid file not specified")
|
||||
return -1, errors.New("conmon pid file not specified")
|
||||
}
|
||||
if !ci.started {
|
||||
return -1, ErrConmonNotStarted
|
||||
|
|
@ -107,7 +105,7 @@ func (ci *ConmonInstance) Pid() (int, error) {
|
|||
|
||||
pid, err := readConmonPidFile(ci.pidFile)
|
||||
if err != nil {
|
||||
return -1, errors.Wrapf(err, "failed to find conmon pid file")
|
||||
return -1, fmt.Errorf("failed to get conmon pid: %w", err)
|
||||
}
|
||||
return pid, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,12 @@ package conmon
|
|||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// These errors are adapted from github.com/containers/podman:libpod/define
|
||||
|
|
@ -29,10 +28,10 @@ var (
|
|||
|
||||
func (ci *ConmonInstance) configurePipeEnv() error {
|
||||
if ci.cmd == nil {
|
||||
return errors.Errorf("conmon instance command must be configured")
|
||||
return errors.New("conmon instance command must be configured")
|
||||
}
|
||||
if ci.started {
|
||||
return errors.Errorf("conmon instance environment cannot be configured after it's started")
|
||||
return errors.New("conmon instance environment cannot be configured after it's started")
|
||||
}
|
||||
// TODO handle PreserveFDs
|
||||
preserveFDs := 0
|
||||
|
|
@ -92,17 +91,17 @@ func readConmonPipeData(pipe *os.File) (int, error) {
|
|||
select {
|
||||
case ss := <-ch:
|
||||
if ss.err != nil {
|
||||
return -1, errors.Wrapf(ss.err, "error received on processing data from conmon pipe")
|
||||
return -1, fmt.Errorf("error received on processing data from conmon pipe: %w", ss.err)
|
||||
}
|
||||
if ss.si.Data < 0 {
|
||||
if ss.si.Message != "" {
|
||||
return ss.si.Data, getOCIRuntimeError(ss.si.Message)
|
||||
}
|
||||
return ss.si.Data, errors.Wrapf(ErrInternal, "conmon invocation failed")
|
||||
return ss.si.Data, fmt.Errorf("conmon invocation failed: %w", ErrInternal)
|
||||
}
|
||||
data = ss.si.Data
|
||||
case <-time.After(1 * time.Minute):
|
||||
return -1, errors.Wrapf(ErrInternal, "conmon invocation timeout")
|
||||
return -1, fmt.Errorf("conmon invocation timeout: %w", ErrInternal)
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
|
@ -117,16 +116,16 @@ func getOCIRuntimeError(runtimeMsg string) error {
|
|||
if includeFullOutput {
|
||||
errStr = runtimeMsg
|
||||
}
|
||||
return errors.Wrapf(ErrOCIRuntimePermissionDenied, "%s", strings.Trim(errStr, "\n"))
|
||||
return fmt.Errorf("%s: %w", strings.Trim(errStr, "\n"), ErrOCIRuntimePermissionDenied)
|
||||
}
|
||||
if match := regexp.MustCompile("(?i).*executable file not found in.*|.*no such file or directory.*").FindString(runtimeMsg); match != "" {
|
||||
errStr := match
|
||||
if includeFullOutput {
|
||||
errStr = runtimeMsg
|
||||
}
|
||||
return errors.Wrapf(ErrOCIRuntimeNotFound, "%s", strings.Trim(errStr, "\n"))
|
||||
return fmt.Errorf("%s: %w", strings.Trim(errStr, "\n"), ErrOCIRuntimeNotFound)
|
||||
}
|
||||
return errors.Wrapf(ErrOCIRuntime, "%s", strings.Trim(runtimeMsg, "\n"))
|
||||
return fmt.Errorf("%s: %w", strings.Trim(runtimeMsg, "\n"), ErrOCIRuntime)
|
||||
}
|
||||
|
||||
// writeConmonPipeData writes data to a pipe. The actual content does not matter
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package conmon_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
|
@ -9,7 +10,6 @@ import (
|
|||
"github.com/containers/conmon/runner/conmon"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue