Skip to content

Commit

Permalink
Consistently use WithError when logging errors instead of %s
Browse files Browse the repository at this point in the history
Signed-off-by: apostasie <spam_blackhole@farcloser.world>
  • Loading branch information
apostasie committed Jan 22, 2025
1 parent 4125210 commit cc2b9c1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/nerdctl/container/container_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions pkg/infoutil/infoutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
}

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/logging/jsonfile/jsonfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit cc2b9c1

Please sign in to comment.