Skip to content

Commit 2a75093

Browse files
committed
Consistently use WithError when logging errors instead of %s
Signed-off-by: apostasie <[email protected]>
1 parent 17bbdff commit 2a75093

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

cmd/nerdctl/container/container_run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ func runAction(cmd *cobra.Command, args []string) error {
386386
return
387387
}
388388
if err := netManager.CleanupNetworking(ctx, c); err != nil {
389-
log.L.Warnf("failed to clean up container networking: %s", err)
389+
log.L.WithError(err).Warnf("failed to clean up container networking")
390390
}
391391
if err := container.RemoveContainer(ctx, c, createOpt.GOptions, true, true, client); err != nil {
392392
log.L.WithError(err).Warnf("failed to remove container %s", id)

pkg/infoutil/infoutil.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ func ServerSemVer(ctx context.Context, client *containerd.Client) (*semver.Versi
160160
func buildctlVersion() dockercompat.ComponentVersion {
161161
buildctlBinary, err := buildkitutil.BuildctlBinary()
162162
if err != nil {
163-
log.L.Warnf("unable to determine buildctl version: %s", err.Error())
163+
log.L.WithError(err).Warnf("unable to determine buildctl version")
164164
return dockercompat.ComponentVersion{Name: "buildctl"}
165165
}
166166

167167
stdout, err := exec.Command(buildctlBinary, "--version").Output()
168168
if err != nil {
169-
log.L.Warnf("unable to determine buildctl version: %s", err.Error())
169+
log.L.WithError(err).Warnf("unable to determine buildctl version")
170170
return dockercompat.ComponentVersion{Name: "buildctl"}
171171
}
172172

@@ -205,7 +205,7 @@ func parseBuildctlVersion(buildctlVersionStdout []byte) (*dockercompat.Component
205205
func runcVersion() dockercompat.ComponentVersion {
206206
stdout, err := exec.Command("runc", "--version").Output()
207207
if err != nil {
208-
log.L.Warnf("unable to determine runc version: %s", err.Error())
208+
log.L.WithError(err).Warnf("unable to determine runc version")
209209
return dockercompat.ComponentVersion{Name: "runc"}
210210
}
211211
v, err := parseRuncVersion(stdout)

pkg/logging/jsonfile/jsonfile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func Decode(stdout, stderr io.Writer, r io.Reader, timestamps bool, since string
146146
// Write out the entry directly
147147
err := writeEntry(&e, stdout, stderr, now, timestamps, since, until)
148148
if err != nil {
149-
log.L.Errorf("error while writing log entry to output stream: %s", err)
149+
log.L.WithError(err).Errorf("error while writing log entry to output stream")
150150
}
151151
}
152152

pkg/logging/logging.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func startTail(ctx context.Context, logName string, w *fsnotify.Watcher) (bool,
264264
log.L.Debugf("Received unexpected fsnotify event: %v, retrying", e)
265265
}
266266
case err := <-w.Errors:
267-
log.L.Debugf("Received fsnotify watch error, retrying unless no more retries left, retries: %d, error: %s", errRetry, err)
267+
log.L.WithError(err).Debugf("Received fsnotify watch error, retrying unless no more retries left, retries: %d", errRetry)
268268
if errRetry == 0 {
269269
return false, err
270270
}

0 commit comments

Comments
 (0)