aboutsummaryrefslogtreecommitdiff
path: root/libpod/events
diff options
context:
space:
mode:
authorSascha Grunert <sgrunert@redhat.com>2022-07-05 11:42:22 +0200
committerSascha Grunert <sgrunert@redhat.com>2022-07-05 16:06:32 +0200
commit251d91699de4e9aaab53ab6fea262d4b6bdaae8e (patch)
tree1995c85a69f48bf129565ca60ea0b3d6205a04b4 /libpod/events
parent340eeed0cb20855f1e6d2670704cfe67df3314f6 (diff)
downloadpodman-251d91699de4e9aaab53ab6fea262d4b6bdaae8e.tar.gz
podman-251d91699de4e9aaab53ab6fea262d4b6bdaae8e.tar.bz2
podman-251d91699de4e9aaab53ab6fea262d4b6bdaae8e.zip
libpod: 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 'libpod/events')
-rw-r--r--libpod/events/config.go3
-rw-r--r--libpod/events/events.go8
-rw-r--r--libpod/events/events_linux.go6
-rw-r--r--libpod/events/events_unsupported.go2
-rw-r--r--libpod/events/filters.go10
-rw-r--r--libpod/events/journal_linux.go23
-rw-r--r--libpod/events/logfile.go6
7 files changed, 29 insertions, 29 deletions
diff --git a/libpod/events/config.go b/libpod/events/config.go
index a678baa2d..4ea45a00e 100644
--- a/libpod/events/config.go
+++ b/libpod/events/config.go
@@ -2,9 +2,8 @@ package events
import (
"context"
+ "errors"
"time"
-
- "github.com/pkg/errors"
)
// EventerType ...
diff --git a/libpod/events/events.go b/libpod/events/events.go
index a8001ab95..764481e51 100644
--- a/libpod/events/events.go
+++ b/libpod/events/events.go
@@ -2,16 +2,16 @@ package events
import (
"encoding/json"
+ "errors"
"fmt"
"time"
"github.com/containers/storage/pkg/stringid"
- "github.com/pkg/errors"
)
// ErrNoJournaldLogging indicates that there is no journald logging
// supported (requires libsystemd)
-var ErrNoJournaldLogging = errors.New("No support for journald logging")
+var ErrNoJournaldLogging = errors.New("no support for journald logging")
// String returns a string representation of EventerType
func (et EventerType) String() string {
@@ -140,7 +140,7 @@ func StringToType(name string) (Type, error) {
case "":
return "", ErrEventTypeBlank
}
- return "", errors.Errorf("unknown event type %q", name)
+ return "", fmt.Errorf("unknown event type %q", name)
}
// StringToStatus converts a string to an Event Status
@@ -225,5 +225,5 @@ func StringToStatus(name string) (Status, error) {
case Untag.String():
return Untag, nil
}
- return "", errors.Errorf("unknown event status %q", name)
+ return "", fmt.Errorf("unknown event status %q", name)
}
diff --git a/libpod/events/events_linux.go b/libpod/events/events_linux.go
index 4320f2190..e7801af5b 100644
--- a/libpod/events/events_linux.go
+++ b/libpod/events/events_linux.go
@@ -1,9 +1,9 @@
package events
import (
+ "fmt"
"strings"
- "github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -14,7 +14,7 @@ func NewEventer(options EventerOptions) (Eventer, error) {
case strings.ToUpper(Journald.String()):
eventer, err := newEventJournalD(options)
if err != nil {
- return nil, errors.Wrapf(err, "eventer creation")
+ return nil, fmt.Errorf("eventer creation: %w", err)
}
return eventer, nil
case strings.ToUpper(LogFile.String()):
@@ -24,6 +24,6 @@ func NewEventer(options EventerOptions) (Eventer, error) {
case strings.ToUpper(Memory.String()):
return NewMemoryEventer(), nil
default:
- return nil, errors.Errorf("unknown event logger type: %s", strings.ToUpper(options.EventerType))
+ return nil, fmt.Errorf("unknown event logger type: %s", strings.ToUpper(options.EventerType))
}
}
diff --git a/libpod/events/events_unsupported.go b/libpod/events/events_unsupported.go
index 25c175524..d766402a9 100644
--- a/libpod/events/events_unsupported.go
+++ b/libpod/events/events_unsupported.go
@@ -3,7 +3,7 @@
package events
-import "github.com/pkg/errors"
+import "errors"
// NewEventer creates an eventer based on the eventer type
func NewEventer(options EventerOptions) (Eventer, error) {
diff --git a/libpod/events/filters.go b/libpod/events/filters.go
index 64c162db2..d5b96e7ec 100644
--- a/libpod/events/filters.go
+++ b/libpod/events/filters.go
@@ -1,11 +1,11 @@
package events
import (
+ "fmt"
"strings"
"time"
"github.com/containers/podman/v4/pkg/util"
- "github.com/pkg/errors"
)
func generateEventFilter(filter, filterValue string) (func(e *Event) bool, error) {
@@ -74,7 +74,7 @@ func generateEventFilter(filter, filterValue string) (func(e *Event) bool, error
return found
}, nil
}
- return nil, errors.Errorf("%s is an invalid filter", filter)
+ return nil, fmt.Errorf("%s is an invalid filter", filter)
}
func generateEventSinceOption(timeSince time.Time) func(e *Event) bool {
@@ -92,7 +92,7 @@ func generateEventUntilOption(timeUntil time.Time) func(e *Event) bool {
func parseFilter(filter string) (string, string, error) {
filterSplit := strings.SplitN(filter, "=", 2)
if len(filterSplit) != 2 {
- return "", "", errors.Errorf("%s is an invalid filter", filter)
+ return "", "", fmt.Errorf("%s is an invalid filter", filter)
}
return filterSplit[0], filterSplit[1], nil
}
@@ -137,7 +137,7 @@ func generateEventFilters(filters []string, since, until string) (map[string][]E
if len(since) > 0 {
timeSince, err := util.ParseInputTime(since, true)
if err != nil {
- return nil, errors.Wrapf(err, "unable to convert since time of %s", since)
+ return nil, fmt.Errorf("unable to convert since time of %s: %w", since, err)
}
filterFunc := generateEventSinceOption(timeSince)
filterMap["since"] = []EventFilter{filterFunc}
@@ -146,7 +146,7 @@ func generateEventFilters(filters []string, since, until string) (map[string][]E
if len(until) > 0 {
timeUntil, err := util.ParseInputTime(until, false)
if err != nil {
- return nil, errors.Wrapf(err, "unable to convert until time of %s", until)
+ return nil, fmt.Errorf("unable to convert until time of %s: %w", until, err)
}
filterFunc := generateEventUntilOption(timeUntil)
filterMap["until"] = []EventFilter{filterFunc}
diff --git a/libpod/events/journal_linux.go b/libpod/events/journal_linux.go
index 036638d34..0a0a768d0 100644
--- a/libpod/events/journal_linux.go
+++ b/libpod/events/journal_linux.go
@@ -6,13 +6,14 @@ package events
import (
"context"
"encoding/json"
+ "errors"
+ "fmt"
"strconv"
"time"
"github.com/containers/podman/v4/pkg/util"
"github.com/coreos/go-systemd/v22/journal"
"github.com/coreos/go-systemd/v22/sdjournal"
- "github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -73,7 +74,7 @@ func (e EventJournalD) Read(ctx context.Context, options ReadOptions) error {
defer close(options.EventChannel)
filterMap, err := generateEventFilters(options.Filters, options.Since, options.Until)
if err != nil {
- return errors.Wrapf(err, "failed to parse event filters")
+ return fmt.Errorf("failed to parse event filters: %w", err)
}
var untilTime time.Time
@@ -96,29 +97,29 @@ func (e EventJournalD) Read(ctx context.Context, options ReadOptions) error {
// match only podman journal entries
podmanJournal := sdjournal.Match{Field: "SYSLOG_IDENTIFIER", Value: "podman"}
if err := j.AddMatch(podmanJournal.String()); err != nil {
- return errors.Wrap(err, "failed to add journal filter for event log")
+ return fmt.Errorf("failed to add journal filter for event log: %w", err)
}
if len(options.Since) == 0 && len(options.Until) == 0 && options.Stream {
if err := j.SeekTail(); err != nil {
- return errors.Wrap(err, "failed to seek end of journal")
+ return fmt.Errorf("failed to seek end of journal: %w", err)
}
// After SeekTail calling Next moves to a random entry.
// To prevent this we have to call Previous first.
// see: https://bugs.freedesktop.org/show_bug.cgi?id=64614
if _, err := j.Previous(); err != nil {
- return errors.Wrap(err, "failed to move journal cursor to previous entry")
+ return fmt.Errorf("failed to move journal cursor to previous entry: %w", err)
}
}
// the api requires a next|prev before getting a cursor
if _, err := j.Next(); err != nil {
- return errors.Wrap(err, "failed to move journal cursor to next entry")
+ return fmt.Errorf("failed to move journal cursor to next entry: %w", err)
}
prevCursor, err := j.GetCursor()
if err != nil {
- return errors.Wrap(err, "failed to get journal cursor")
+ return fmt.Errorf("failed to get journal cursor: %w", err)
}
for {
select {
@@ -130,11 +131,11 @@ func (e EventJournalD) Read(ctx context.Context, options ReadOptions) error {
}
if _, err := j.Next(); err != nil {
- return errors.Wrap(err, "failed to move journal cursor to next entry")
+ return fmt.Errorf("failed to move journal cursor to next entry: %w", err)
}
newCursor, err := j.GetCursor()
if err != nil {
- return errors.Wrap(err, "failed to get journal cursor")
+ return fmt.Errorf("failed to get journal cursor: %w", err)
}
if prevCursor == newCursor {
if !options.Stream || (len(options.Until) > 0 && time.Now().After(untilTime)) {
@@ -151,14 +152,14 @@ func (e EventJournalD) Read(ctx context.Context, options ReadOptions) error {
entry, err := j.GetEntry()
if err != nil {
- return errors.Wrap(err, "failed to read journal entry")
+ return fmt.Errorf("failed to read journal entry: %w", err)
}
newEvent, err := newEventFromJournalEntry(entry)
if err != nil {
// We can't decode this event.
// Don't fail hard - that would make events unusable.
// Instead, log and continue.
- if errors.Cause(err) != ErrEventTypeBlank {
+ if !errors.Is(err, ErrEventTypeBlank) {
logrus.Errorf("Unable to decode event: %v", err)
}
continue
diff --git a/libpod/events/logfile.go b/libpod/events/logfile.go
index 21fdd8027..4dafd8600 100644
--- a/libpod/events/logfile.go
+++ b/libpod/events/logfile.go
@@ -6,6 +6,7 @@ package events
import (
"bufio"
"context"
+ "errors"
"fmt"
"io"
"io/ioutil"
@@ -16,7 +17,6 @@ import (
"github.com/containers/podman/v4/pkg/util"
"github.com/containers/storage/pkg/lockfile"
"github.com/nxadm/tail"
- "github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)
@@ -90,7 +90,7 @@ func (e EventLogFile) Read(ctx context.Context, options ReadOptions) error {
defer close(options.EventChannel)
filterMap, err := generateEventFilters(options.Filters, options.Since, options.Until)
if err != nil {
- return errors.Wrapf(err, "failed to parse event filters")
+ return fmt.Errorf("failed to parse event filters: %w", err)
}
t, err := e.getTail(options)
if err != nil {
@@ -136,7 +136,7 @@ func (e EventLogFile) Read(ctx context.Context, options ReadOptions) error {
case Image, Volume, Pod, System, Container, Network:
// no-op
default:
- return errors.Errorf("event type %s is not valid in %s", event.Type.String(), e.options.LogFilePath)
+ return fmt.Errorf("event type %s is not valid in %s", event.Type.String(), e.options.LogFilePath)
}
if copy && applyFilters(event, filterMap) {
options.EventChannel <- event