summaryrefslogtreecommitdiff
path: root/pkg/hooks
diff options
context:
space:
mode:
authorSascha Grunert <sgrunert@redhat.com>2022-07-06 09:48:36 +0200
committerSascha Grunert <sgrunert@redhat.com>2022-07-08 08:54:47 +0200
commita46f798831df06c472b288db7b34de8536a7ea5a (patch)
treec370fb0fc23b461691906e308b179a50e583228b /pkg/hooks
parent862cc42ddc11ff56b41be128182b748b0843dff3 (diff)
downloadpodman-a46f798831df06c472b288db7b34de8536a7ea5a.tar.gz
podman-a46f798831df06c472b288db7b34de8536a7ea5a.tar.bz2
podman-a46f798831df06c472b288db7b34de8536a7ea5a.zip
pkg: switch to golang native error wrapping
We now use the golang error wrapping format specifier `%w` instead of the deprecated github.com/pkg/errors package. [NO NEW TESTS NEEDED] Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
Diffstat (limited to 'pkg/hooks')
-rw-r--r--pkg/hooks/1.0.0/hook.go8
-rw-r--r--pkg/hooks/1.0.0/when.go9
-rw-r--r--pkg/hooks/exec/exec.go3
-rw-r--r--pkg/hooks/exec/runtimeconfigfilter.go4
-rw-r--r--pkg/hooks/hooks.go3
-rw-r--r--pkg/hooks/read.go13
6 files changed, 20 insertions, 20 deletions
diff --git a/pkg/hooks/1.0.0/hook.go b/pkg/hooks/1.0.0/hook.go
index 244e8800f..71f940a64 100644
--- a/pkg/hooks/1.0.0/hook.go
+++ b/pkg/hooks/1.0.0/hook.go
@@ -3,12 +3,12 @@ package hook
import (
"encoding/json"
+ "errors"
"fmt"
"os"
"regexp"
rspec "github.com/opencontainers/runtime-spec/specs-go"
- "github.com/pkg/errors"
)
// Version is the hook configuration version defined in this package.
@@ -50,16 +50,16 @@ func (hook *Hook) Validate(extensionStages []string) (err error) {
for key, value := range hook.When.Annotations {
if _, err = regexp.Compile(key); err != nil {
- return errors.Wrapf(err, "invalid annotation key %q", key)
+ return fmt.Errorf("invalid annotation key %q: %w", key, err)
}
if _, err = regexp.Compile(value); err != nil {
- return errors.Wrapf(err, "invalid annotation value %q", value)
+ return fmt.Errorf("invalid annotation value %q: %w", value, err)
}
}
for _, command := range hook.When.Commands {
if _, err = regexp.Compile(command); err != nil {
- return errors.Wrapf(err, "invalid command %q", command)
+ return fmt.Errorf("invalid command %q: %w", command, err)
}
}
diff --git a/pkg/hooks/1.0.0/when.go b/pkg/hooks/1.0.0/when.go
index a65af048e..a1351890f 100644
--- a/pkg/hooks/1.0.0/when.go
+++ b/pkg/hooks/1.0.0/when.go
@@ -1,10 +1,11 @@
package hook
import (
+ "errors"
+ "fmt"
"regexp"
rspec "github.com/opencontainers/runtime-spec/specs-go"
- "github.com/pkg/errors"
)
// When holds hook-injection conditions.
@@ -52,12 +53,12 @@ func (when *When) Match(config *rspec.Spec, annotations map[string]string, hasBi
for key, value := range annotations {
match, err = regexp.MatchString(keyPattern, key)
if err != nil {
- return false, errors.Wrap(err, "annotation key")
+ return false, fmt.Errorf("annotation key: %w", err)
}
if match {
match, err = regexp.MatchString(valuePattern, value)
if err != nil {
- return false, errors.Wrap(err, "annotation value")
+ return false, fmt.Errorf("annotation value: %w", err)
}
if match {
break
@@ -82,7 +83,7 @@ func (when *When) Match(config *rspec.Spec, annotations map[string]string, hasBi
for _, cmdPattern := range when.Commands {
match, err := regexp.MatchString(cmdPattern, command)
if err != nil {
- return false, errors.Wrap(err, "command")
+ return false, fmt.Errorf("command: %w", err)
}
if match {
return true, nil
diff --git a/pkg/hooks/exec/exec.go b/pkg/hooks/exec/exec.go
index 2b7bc5f31..bc639245f 100644
--- a/pkg/hooks/exec/exec.go
+++ b/pkg/hooks/exec/exec.go
@@ -10,7 +10,6 @@ import (
"time"
rspec "github.com/opencontainers/runtime-spec/specs-go"
- "github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -46,7 +45,7 @@ func Run(ctx context.Context, hook *rspec.Hook, state []byte, stdout io.Writer,
go func() {
err := cmd.Wait()
if err != nil {
- err = errors.Wrapf(err, "executing %v", cmd.Args)
+ err = fmt.Errorf("executing %v: %w", cmd.Args, err)
}
exit <- err
}()
diff --git a/pkg/hooks/exec/runtimeconfigfilter.go b/pkg/hooks/exec/runtimeconfigfilter.go
index 3ab3073b2..72d4b8979 100644
--- a/pkg/hooks/exec/runtimeconfigfilter.go
+++ b/pkg/hooks/exec/runtimeconfigfilter.go
@@ -4,12 +4,12 @@ import (
"bytes"
"context"
"encoding/json"
+ "fmt"
"reflect"
"time"
"github.com/davecgh/go-spew/spew"
spec "github.com/opencontainers/runtime-spec/specs-go"
- "github.com/pkg/errors"
"github.com/pmezard/go-difflib/difflib"
"github.com/sirupsen/logrus"
)
@@ -43,7 +43,7 @@ func RuntimeConfigFilter(ctx context.Context, hooks []spec.Hook, config *spec.Sp
err = json.Unmarshal(data, &newConfig)
if err != nil {
logrus.Debugf("invalid JSON from config-filter hook %d:\n%s", i, string(data))
- return nil, errors.Wrapf(err, "unmarshal output from config-filter hook %d", i)
+ return nil, fmt.Errorf("unmarshal output from config-filter hook %d: %w", i, err)
}
if !reflect.DeepEqual(config, &newConfig) {
diff --git a/pkg/hooks/hooks.go b/pkg/hooks/hooks.go
index ecd5b7dfc..14f98b1de 100644
--- a/pkg/hooks/hooks.go
+++ b/pkg/hooks/hooks.go
@@ -11,7 +11,6 @@ import (
current "github.com/containers/podman/v4/pkg/hooks/1.0.0"
rspec "github.com/opencontainers/runtime-spec/specs-go"
- "github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -105,7 +104,7 @@ func (m *Manager) Hooks(config *rspec.Spec, annotations map[string]string, hasBi
for _, namedHook := range hooks {
match, err := namedHook.hook.When.Match(config, annotations, hasBindMounts)
if err != nil {
- return extensionStageHooks, errors.Wrapf(err, "matching hook %q", namedHook.name)
+ return extensionStageHooks, fmt.Errorf("matching hook %q: %w", namedHook.name, err)
}
if match {
logrus.Debugf("hook %s matched; adding to stages %v", namedHook.name, namedHook.hook.Stages)
diff --git a/pkg/hooks/read.go b/pkg/hooks/read.go
index c48d51f7d..379ed67ef 100644
--- a/pkg/hooks/read.go
+++ b/pkg/hooks/read.go
@@ -3,6 +3,8 @@ package hooks
import (
"encoding/json"
+ "errors"
+ "fmt"
"io/ioutil"
"os"
"path/filepath"
@@ -10,7 +12,6 @@ import (
old "github.com/containers/podman/v4/pkg/hooks/0.1.0"
current "github.com/containers/podman/v4/pkg/hooks/1.0.0"
- "github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -36,7 +37,7 @@ func Read(path string, extensionStages []string) (*current.Hook, error) {
}
hook, err := read(content)
if err != nil {
- return nil, errors.Wrapf(err, "parsing hook %q", path)
+ return nil, fmt.Errorf("parsing hook %q: %w", path, err)
}
err = hook.Validate(extensionStages)
return hook, err
@@ -45,16 +46,16 @@ func Read(path string, extensionStages []string) (*current.Hook, error) {
func read(content []byte) (hook *current.Hook, err error) {
var ver version
if err := json.Unmarshal(content, &ver); err != nil {
- return nil, errors.Wrap(err, "version check")
+ return nil, fmt.Errorf("version check: %w", err)
}
reader, ok := Readers[ver.Version]
if !ok {
- return nil, errors.Errorf("unrecognized hook version: %q", ver.Version)
+ return nil, fmt.Errorf("unrecognized hook version: %q", ver.Version)
}
hook, err = reader(content)
if err != nil {
- return hook, errors.Wrap(err, ver.Version)
+ return hook, fmt.Errorf("%v: %w", ver.Version, err)
}
return hook, err
}
@@ -83,7 +84,7 @@ func ReadDir(path string, extensionStages []string, hooks map[string]*current.Ho
if res == nil {
res = err
} else {
- res = errors.Wrapf(res, "%v", err)
+ res = fmt.Errorf("%v: %w", err, res)
}
continue
}