Skip to content

Commit 17bbdff

Browse files
committed
Consistently use %w instead of %s or %v when wrapping errors
Signed-off-by: apostasie <[email protected]>
1 parent f8e47e8 commit 17bbdff

26 files changed

+52
-52
lines changed

cmd/nerdctl/container/container_create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ func createAction(cmd *cobra.Command, args []string) error {
443443

444444
netFlags, err := loadNetworkFlags(cmd)
445445
if err != nil {
446-
return fmt.Errorf("failed to load networking flags: %s", err)
446+
return fmt.Errorf("failed to load networking flags: %w", err)
447447
}
448448

449449
netManager, err := containerutil.NewNetworkingOptionsManager(createOpt.GOptions, netFlags, client)

cmd/nerdctl/container/container_logs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func getTailArgAsUint(arg string) (uint, error) {
127127
}
128128
num, err := strconv.Atoi(arg)
129129
if err != nil {
130-
return 0, fmt.Errorf("failed to parse `-n/--tail` argument %q: %s", arg, err)
130+
return 0, fmt.Errorf("failed to parse `-n/--tail` argument %q: %w", arg, err)
131131
}
132132
if num < 0 {
133133
return 0, fmt.Errorf("`-n/--tail` argument must be positive, got: %d", num)

cmd/nerdctl/container/container_run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ func runAction(cmd *cobra.Command, args []string) error {
357357

358358
netFlags, err := loadNetworkFlags(cmd)
359359
if err != nil {
360-
return fmt.Errorf("failed to load networking flags: %s", err)
360+
return fmt.Errorf("failed to load networking flags: %w", err)
361361
}
362362

363363
netManager, err := containerutil.NewNetworkingOptionsManager(createOpt.GOptions, netFlags, client)

cmd/nerdctl/container/container_run_network_windows_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func listHnsEndpointsRegex(hnsEndpointNameRegex string) ([]hcsshim.HNSEndpoint,
7373
}
7474
hnsEndpoints, err := hcsshim.HNSListEndpointRequest()
7575
if err != nil {
76-
return nil, fmt.Errorf("failed to list HNS endpoints for request: %s", err)
76+
return nil, fmt.Errorf("failed to list HNS endpoints for request: %w", err)
7777
}
7878

7979
res := []hcsshim.HNSEndpoint{}

pkg/cmd/builder/build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func Build(ctx context.Context, client *containerd.Client, options types.Builder
120120
imageService := client.ImageService()
121121
image, err := imageService.Get(ctx, tags[0])
122122
if err != nil {
123-
return fmt.Errorf("unable to tag image: %s", err)
123+
return fmt.Errorf("unable to tag image: %w", err)
124124
}
125125
for _, targetRef := range tags[1:] {
126126
image.Name = targetRef
@@ -135,7 +135,7 @@ func Build(ctx context.Context, client *containerd.Client, options types.Builder
135135
}
136136
continue
137137
}
138-
return fmt.Errorf("unable to tag image: %s", err)
138+
return fmt.Errorf("unable to tag image: %w", err)
139139
}
140140
}
141141
}

pkg/cmd/container/create.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,19 +230,19 @@ func Create(ctx context.Context, client *containerd.Client, args []string, netMa
230230
cOpts = append(cOpts, restartOpts...)
231231

232232
if err = netManager.VerifyNetworkOptions(ctx); err != nil {
233-
return nil, generateRemoveStateDirFunc(ctx, id, internalLabels), fmt.Errorf("failed to verify networking settings: %s", err)
233+
return nil, generateRemoveStateDirFunc(ctx, id, internalLabels), fmt.Errorf("failed to verify networking settings: %w", err)
234234
}
235235

236236
netOpts, netNewContainerOpts, err := netManager.ContainerNetworkingOpts(ctx, id)
237237
if err != nil {
238-
return nil, generateRemoveOrphanedDirsFunc(ctx, id, dataStore, internalLabels), fmt.Errorf("failed to generate networking spec options: %s", err)
238+
return nil, generateRemoveOrphanedDirsFunc(ctx, id, dataStore, internalLabels), fmt.Errorf("failed to generate networking spec options: %w", err)
239239
}
240240
opts = append(opts, netOpts...)
241241
cOpts = append(cOpts, netNewContainerOpts...)
242242

243243
netLabelOpts, err := netManager.InternalNetworkingOptionLabels(ctx)
244244
if err != nil {
245-
return nil, generateRemoveOrphanedDirsFunc(ctx, id, dataStore, internalLabels), fmt.Errorf("failed to generate internal networking labels: %s", err)
245+
return nil, generateRemoveOrphanedDirsFunc(ctx, id, dataStore, internalLabels), fmt.Errorf("failed to generate internal networking labels: %w", err)
246246
}
247247

248248
envs = append(envs, "HOSTNAME="+netLabelOpts.Hostname)

pkg/cmd/container/logs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func Logs(ctx context.Context, client *containerd.Client, container string, opti
8585
} else {
8686
waitCh, err := task.Wait(ctx)
8787
if err != nil {
88-
return fmt.Errorf("failed to get wait channel for task %#v: %s", task, err)
88+
return fmt.Errorf("failed to get wait channel for task %#v: %w", task, err)
8989
}
9090

9191
// Setup goroutine to send stop event if container task finishes:

pkg/cmd/container/remove.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func RemoveContainer(ctx context.Context, c containerd.Container, globalOptions
194194
if err == nil {
195195
networkManager, err := containerutil.NewNetworkingOptionsManager(globalOptions, netOpts, client)
196196
if err != nil {
197-
retErr = fmt.Errorf("failed to instantiate network options manager: %s", err)
197+
retErr = fmt.Errorf("failed to instantiate network options manager: %w", err)
198198
return
199199
}
200200

pkg/cmd/container/top_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func parsePSOutput(output []byte, procs []uint32) (*ContainerTopOKBody, error) {
232232
}
233233
p, err = strconv.Atoi(fields[pidIndex])
234234
if err != nil {
235-
return nil, fmt.Errorf("unexpected pid '%s': %s", fields[pidIndex], err)
235+
return nil, fmt.Errorf("unexpected pid '%s': %w", fields[pidIndex], err)
236236
}
237237

238238
if hasPid(procs, p) {

pkg/composer/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (c *Composer) createServiceContainer(ctx context.Context, service *servicep
159159
// check if container already exists
160160
exists, err := c.containerExists(ctx, container.Name, service.Unparsed.Name)
161161
if err != nil {
162-
return "", fmt.Errorf("error while checking for containers with name %q: %s", container.Name, err)
162+
return "", fmt.Errorf("error while checking for containers with name %q: %w", container.Name, err)
163163
}
164164

165165
// delete container if it already exists and force-recreate is enabled
@@ -172,7 +172,7 @@ func (c *Composer) createServiceContainer(ctx context.Context, service *servicep
172172
log.G(ctx).Debugf("Container %q already exists and force-created is enabled, deleting", container.Name)
173173
delCmd := c.createNerdctlCmd(ctx, "rm", "-f", container.Name)
174174
if err = delCmd.Run(); err != nil {
175-
return "", fmt.Errorf("could not delete container %q: %s", container.Name, err)
175+
return "", fmt.Errorf("could not delete container %q: %w", container.Name, err)
176176
}
177177
log.G(ctx).Infof("Re-creating container %s", container.Name)
178178
} else {

0 commit comments

Comments
 (0)