From cc2b9c19feac0fc5771007544d467779dd83ce0a Mon Sep 17 00:00:00 2001 From: apostasie Date: Wed, 22 Jan 2025 13:35:31 -0800 Subject: [PATCH] Consistently use WithError when logging errors instead of %s Signed-off-by: apostasie --- cmd/nerdctl/container/container_run.go | 2 +- pkg/infoutil/infoutil.go | 6 +++--- pkg/logging/jsonfile/jsonfile.go | 2 +- pkg/logging/logging.go | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/nerdctl/container/container_run.go b/cmd/nerdctl/container/container_run.go index 1a0639749c9..31a9dacb5b1 100644 --- a/cmd/nerdctl/container/container_run.go +++ b/cmd/nerdctl/container/container_run.go @@ -386,7 +386,7 @@ func runAction(cmd *cobra.Command, args []string) error { return } if err := netManager.CleanupNetworking(ctx, c); err != nil { - log.L.Warnf("failed to clean up container networking: %s", err) + log.L.WithError(err).Warnf("failed to clean up container networking") } if err := container.RemoveContainer(ctx, c, createOpt.GOptions, true, true, client); err != nil { log.L.WithError(err).Warnf("failed to remove container %s", id) diff --git a/pkg/infoutil/infoutil.go b/pkg/infoutil/infoutil.go index 43041dd5d1b..2886c9fe049 100644 --- a/pkg/infoutil/infoutil.go +++ b/pkg/infoutil/infoutil.go @@ -160,13 +160,13 @@ func ServerSemVer(ctx context.Context, client *containerd.Client) (*semver.Versi func buildctlVersion() dockercompat.ComponentVersion { buildctlBinary, err := buildkitutil.BuildctlBinary() if err != nil { - log.L.Warnf("unable to determine buildctl version: %s", err.Error()) + log.L.WithError(err).Warnf("unable to determine buildctl version") return dockercompat.ComponentVersion{Name: "buildctl"} } stdout, err := exec.Command(buildctlBinary, "--version").Output() if err != nil { - log.L.Warnf("unable to determine buildctl version: %s", err.Error()) + log.L.WithError(err).Warnf("unable to determine buildctl version") return dockercompat.ComponentVersion{Name: "buildctl"} } @@ -205,7 +205,7 @@ func parseBuildctlVersion(buildctlVersionStdout []byte) (*dockercompat.Component func runcVersion() dockercompat.ComponentVersion { stdout, err := exec.Command("runc", "--version").Output() if err != nil { - log.L.Warnf("unable to determine runc version: %s", err.Error()) + log.L.WithError(err).Warnf("unable to determine runc version") return dockercompat.ComponentVersion{Name: "runc"} } v, err := parseRuncVersion(stdout) diff --git a/pkg/logging/jsonfile/jsonfile.go b/pkg/logging/jsonfile/jsonfile.go index 2e47b836819..a1693cda0d7 100644 --- a/pkg/logging/jsonfile/jsonfile.go +++ b/pkg/logging/jsonfile/jsonfile.go @@ -146,7 +146,7 @@ func Decode(stdout, stderr io.Writer, r io.Reader, timestamps bool, since string // Write out the entry directly err := writeEntry(&e, stdout, stderr, now, timestamps, since, until) if err != nil { - log.L.Errorf("error while writing log entry to output stream: %s", err) + log.L.WithError(err).Errorf("error while writing log entry to output stream") } } diff --git a/pkg/logging/logging.go b/pkg/logging/logging.go index c16cbcd3986..15663acc868 100644 --- a/pkg/logging/logging.go +++ b/pkg/logging/logging.go @@ -264,7 +264,7 @@ func startTail(ctx context.Context, logName string, w *fsnotify.Watcher) (bool, log.L.Debugf("Received unexpected fsnotify event: %v, retrying", e) } case err := <-w.Errors: - log.L.Debugf("Received fsnotify watch error, retrying unless no more retries left, retries: %d, error: %s", errRetry, err) + log.L.WithError(err).Debugf("Received fsnotify watch error, retrying unless no more retries left, retries: %d", errRetry) if errRetry == 0 { return false, err }