Skip to content

Commit 1bde781

Browse files
authored
Merge pull request #679 from austinvazquez/remove-errors
chore: remove pkg/errors dependency
2 parents 0b71a80 + def5a83 commit 1bde781

File tree

26 files changed

+198
-218
lines changed

26 files changed

+198
-218
lines changed

agent/drive_handler.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"github.com/firecracker-microvm/firecracker-containerd/internal"
2828
drivemount "github.com/firecracker-microvm/firecracker-containerd/proto/service/drivemount/ttrpc"
2929
"github.com/gogo/protobuf/types"
30-
"github.com/pkg/errors"
3130
)
3231

3332
const (
@@ -183,7 +182,7 @@ func (dh driveHandler) MountDrive(ctx context.Context, req *drivemount.MountDriv
183182

184183
err := os.MkdirAll(req.DestinationPath, 0700)
185184
if err != nil {
186-
return nil, errors.Wrapf(err, "failed to create drive mount destination %q", req.DestinationPath)
185+
return nil, fmt.Errorf("failed to create drive mount destination %q: %w", req.DestinationPath, err)
187186
}
188187

189188
// Retry the mount in the case of failure a fixed number of times. This works around a rare issue
@@ -210,12 +209,10 @@ func (dh driveHandler) MountDrive(ctx context.Context, req *drivemount.MountDriv
210209
continue
211210
}
212211

213-
return nil, errors.Wrapf(err, "non-retryable failure mounting drive from %q to %q",
214-
drive.Path(), req.DestinationPath)
212+
return nil, fmt.Errorf("non-retryable failure mounting drive from %q to %q: %w", drive.Path(), req.DestinationPath, err)
215213
}
216214

217-
return nil, errors.Errorf("exhausted retries mounting drive from %q to %q",
218-
drive.Path(), req.DestinationPath)
215+
return nil, fmt.Errorf("exhausted retries mounting drive from %q to %q", drive.Path(), req.DestinationPath)
219216
}
220217

221218
func (dh driveHandler) UnmountDrive(ctx context.Context, req *drivemount.UnmountDriveRequest) (*types.Empty, error) {
@@ -229,23 +226,18 @@ func (dh driveHandler) UnmountDrive(ctx context.Context, req *drivemount.Unmount
229226
return &types.Empty{}, nil
230227
}
231228

232-
return nil, errors.Errorf("failed to unmount the drive %q",
233-
drive.Path())
229+
return nil, fmt.Errorf("failed to unmount the drive %q", drive.Path())
234230
}
235231

236232
func isSystemDir(path string) error {
237233
resolvedDest, err := evalAnySymlinks(path)
238234
if err != nil {
239-
return errors.Wrapf(err,
240-
"failed to evaluate any symlinks in drive ummount destination %q", path)
235+
return fmt.Errorf("failed to evaluate any symlinks in drive unmount destination %q: %w", path, err)
241236
}
242237

243238
for _, systemDir := range bannedSystemDirs {
244239
if isOrUnderDir(resolvedDest, systemDir) {
245-
return errors.Errorf(
246-
"drive mount destination %q resolves to path %q under banned system directory %q",
247-
path, resolvedDest, systemDir,
248-
)
240+
return fmt.Errorf("drive mount destination %q resolves to path %q under banned system directory %q", path, resolvedDest, systemDir)
249241
}
250242
}
251243

agent/service.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
taskAPI "github.com/containerd/containerd/runtime/v2/task"
3131
"github.com/gogo/protobuf/types"
3232
"github.com/hashicorp/go-multierror"
33-
"github.com/pkg/errors"
3433
"github.com/sirupsen/logrus"
3534
"golang.org/x/sys/unix"
3635

@@ -157,7 +156,7 @@ func (ts *TaskService) Create(requestCtx context.Context, req *taskAPI.CreateTas
157156
// this is technically validated earlier by containerd, but is added here too for extra safety
158157
taskExecID, err := TaskExecID(taskID, execID)
159158
if err != nil {
160-
return nil, errors.Wrap(err, "invalid task and/or exec ID")
159+
return nil, fmt.Errorf("invalid task and/or exec ID: %w", err)
161160
}
162161

163162
logger := log.G(requestCtx).WithField("TaskID", taskID).WithField("ExecID", execID)
@@ -174,7 +173,7 @@ func (ts *TaskService) Create(requestCtx context.Context, req *taskAPI.CreateTas
174173

175174
extraData, err := unmarshalExtraData(req.Options)
176175
if err != nil {
177-
return nil, errors.Wrap(err, "failed to unmarshal extra data")
176+
return nil, fmt.Errorf("failed to unmarshal extra data: %w", err)
178177
}
179178

180179
// Just provide runc the options it knows about, not our wrapper
@@ -184,7 +183,7 @@ func (ts *TaskService) Create(requestCtx context.Context, req *taskAPI.CreateTas
184183
ts.addCleanup(taskExecID, func() error {
185184
err := os.RemoveAll(bundleDir.RootPath())
186185
if err != nil {
187-
return errors.Wrapf(err, "failed to remove bundle path %q", bundleDir.RootPath())
186+
return fmt.Errorf("failed to remove bundle path %q: %w", bundleDir.RootPath(), err)
188187
}
189188
return nil
190189
})
@@ -195,22 +194,22 @@ func (ts *TaskService) Create(requestCtx context.Context, req *taskAPI.CreateTas
195194
// the bundledir was not created. Create it here.
196195
if isVMLocalRootFs {
197196
if err := os.MkdirAll(bundleDir.RootfsPath(), 0700); err != nil {
198-
return nil, errors.Wrapf(err, "Failed to create bundle's rootfs path from inside the vm %q", bundleDir.RootfsPath())
197+
return nil, fmt.Errorf("Failed to create bundle's rootfs path from inside the vm %q: %w", bundleDir.RootfsPath(), err)
199198
}
200199
}
201200

202201
// check the rootfs dir has been created (presumed to be by a previous MountDrive call)
203202
rootfsStat, err := os.Stat(bundleDir.RootfsPath())
204203
if err != nil {
205-
return nil, errors.Wrapf(err, "failed to stat bundle's rootfs path %q", bundleDir.RootfsPath())
204+
return nil, fmt.Errorf("failed to stat bundle's rootfs path %q: %w", bundleDir.RootfsPath(), err)
206205
}
207206
if !rootfsStat.IsDir() {
208-
return nil, errors.Errorf("bundle's rootfs path %q is not a dir", bundleDir.RootfsPath())
207+
return nil, fmt.Errorf("bundle's rootfs path %q is not a dir", bundleDir.RootfsPath())
209208
}
210209
ts.addCleanup(taskExecID, func() error {
211210
err := mount.UnmountAll(bundleDir.RootfsPath(), unix.MNT_DETACH)
212211
if err != nil {
213-
return errors.Wrapf(err, "failed to unmount bundle rootfs %q", bundleDir.RootfsPath())
212+
return fmt.Errorf("failed to unmount bundle rootfs %q: %w", bundleDir.RootfsPath(), err)
214213
}
215214
return nil
216215
})
@@ -228,12 +227,12 @@ func (ts *TaskService) Create(requestCtx context.Context, req *taskAPI.CreateTas
228227
}
229228
specData, err = vm.UpdateUserInSpec(requestCtx, specData, rootfsMount)
230229
if err != nil {
231-
return nil, errors.Wrap(err, "failed to update spec")
230+
return nil, fmt.Errorf("failed to update spec: %w", err)
232231
}
233232
}
234233
err = bundleDir.OCIConfig().Write(specData)
235234
if err != nil {
236-
return nil, errors.Wrap(err, "failed to write oci config file")
235+
return nil, fmt.Errorf("failed to write oci config file: %w", err)
237236
}
238237

239238
var ioConnectorSet vm.IOProxy
@@ -244,7 +243,7 @@ func (ts *TaskService) Create(requestCtx context.Context, req *taskAPI.CreateTas
244243
// Override the incoming stdio FIFOs, which have paths from the host that we can't use
245244
fifoSet, err := cio.NewFIFOSetInDir(bundleDir.RootPath(), taskExecID, req.Terminal)
246245
if err != nil {
247-
err = errors.Wrap(err, "failed to open stdio FIFOs")
246+
err = fmt.Errorf("failed to open stdio FIFOs: %w", err)
248247
logger.WithError(err).Error()
249248
return nil, err
250249
}
@@ -331,7 +330,7 @@ func (ts *TaskService) Delete(requestCtx context.Context, req *taskAPI.DeleteReq
331330
// this is technically validated earlier by containerd, but is added here too for extra safety
332331
taskExecID, err := TaskExecID(taskID, execID)
333332
if err != nil {
334-
return nil, errors.Wrap(err, "invalid task and/or exec ID")
333+
return nil, fmt.Errorf("invalid task and/or exec ID: %w", err)
335334
}
336335

337336
log.G(requestCtx).WithFields(logrus.Fields{"id": taskID, "exec_id": execID}).Debug("delete")
@@ -343,7 +342,7 @@ func (ts *TaskService) Delete(requestCtx context.Context, req *taskAPI.DeleteReq
343342

344343
err = ts.doCleanup(taskExecID)
345344
if err != nil {
346-
return nil, errors.Wrapf(err, "failed to cleanup task %q exec %q", taskID, execID)
345+
return nil, fmt.Errorf("failed to cleanup task %q exec %q: %w", taskID, execID, err)
347346
}
348347

349348
log.G(requestCtx).WithFields(logrus.Fields{
@@ -437,7 +436,7 @@ func (ts *TaskService) Exec(requestCtx context.Context, req *taskAPI.ExecProcess
437436
// this is technically validated earlier by containerd, but is added here too for extra safety
438437
taskExecID, err := TaskExecID(taskID, execID)
439438
if err != nil {
440-
return nil, errors.Wrap(err, "invalid task and/or exec ID")
439+
return nil, fmt.Errorf("invalid task and/or exec ID: %w", err)
441440
}
442441

443442
logger := log.G(requestCtx).WithField("TaskID", taskID).WithField("ExecID", execID)
@@ -454,7 +453,7 @@ func (ts *TaskService) Exec(requestCtx context.Context, req *taskAPI.ExecProcess
454453

455454
extraData, err := unmarshalExtraData(req.Spec)
456455
if err != nil {
457-
return nil, errors.Wrap(err, "failed to unmarshal extra data")
456+
return nil, fmt.Errorf("failed to unmarshal extra data: %w", err)
458457
}
459458

460459
// Just provide runc the options it knows about, not our wrapper
@@ -470,7 +469,7 @@ func (ts *TaskService) Exec(requestCtx context.Context, req *taskAPI.ExecProcess
470469
// Override the incoming stdio FIFOs, which have paths from the host that we can't use
471470
fifoSet, err := cio.NewFIFOSetInDir(bundleDir.RootPath(), taskExecID, req.Terminal)
472471
if err != nil {
473-
err = errors.Wrap(err, "failed to open stdio FIFOs")
472+
err = fmt.Errorf("failed to open stdio FIFOs: %w", err)
474473
logger.WithError(err).Error()
475474
return nil, err
476475
}

config/config.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ package config
1515

1616
import (
1717
"encoding/json"
18+
"fmt"
1819
"io/ioutil"
1920
"os"
2021

21-
"github.com/pkg/errors"
22-
2322
"github.com/firecracker-microvm/firecracker-containerd/internal"
2423
"github.com/firecracker-microvm/firecracker-containerd/internal/debug"
2524
"github.com/firecracker-microvm/firecracker-containerd/proto"
@@ -81,7 +80,7 @@ func LoadConfig(path string) (*Config, error) {
8180

8281
data, err := ioutil.ReadFile(path)
8382
if err != nil {
84-
return nil, errors.Wrapf(err, "failed to read config from %q", path)
83+
return nil, fmt.Errorf("failed to read config from %q: %w", path, err)
8584
}
8685

8786
cfg := &Config{
@@ -103,7 +102,7 @@ func LoadConfig(path string) (*Config, error) {
103102
}
104103

105104
if err := json.Unmarshal(data, cfg); err != nil {
106-
return nil, errors.Wrapf(err, "failed to unmarshal config from %q", path)
105+
return nil, fmt.Errorf("failed to unmarshal config from %q: %w", path, err)
107106
}
108107

109108
cfg.DebugHelper, err = debug.New(cfg.LogLevels...)

examples/taskworkflow.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/containerd/containerd/cio"
2929
"github.com/containerd/containerd/namespaces"
3030
"github.com/containerd/containerd/oci"
31-
"github.com/pkg/errors"
3231

3332
fcclient "github.com/firecracker-microvm/firecracker-containerd/firecracker-control/client"
3433
"github.com/firecracker-microvm/firecracker-containerd/proto"
@@ -63,7 +62,7 @@ func taskWorkflow(containerCIDR, gateway, snapshotter string) (err error) {
6362
log.Println("Creating containerd client")
6463
client, err := containerd.New(containerdAddress)
6564
if err != nil {
66-
return errors.Wrapf(err, "creating client")
65+
return fmt.Errorf("creating client: %w", err)
6766
}
6867

6968
defer client.Close()
@@ -75,7 +74,7 @@ func taskWorkflow(containerCIDR, gateway, snapshotter string) (err error) {
7574
containerd.WithPullSnapshotter(snapshotter),
7675
)
7776
if err != nil {
78-
return errors.Wrapf(err, "creating container")
77+
return fmt.Errorf("creating container: %w", err)
7978
}
8079

8180
fcClient, err := fcclient.New(containerdTTRPCAddress)
@@ -110,7 +109,7 @@ func taskWorkflow(containerCIDR, gateway, snapshotter string) (err error) {
110109

111110
_, err = fcClient.CreateVM(ctx, createVMRequest)
112111
if err != nil {
113-
return errors.Wrap(err, "failed to create VM")
112+
return fmt.Errorf("failed to create VM: %w", err)
114113
}
115114

116115
defer func() {
@@ -143,22 +142,20 @@ func taskWorkflow(containerCIDR, gateway, snapshotter string) (err error) {
143142

144143
task, err := container.NewTask(ctx, cio.NewCreator(cio.WithStdio))
145144
if err != nil {
146-
return errors.Wrapf(err, "creating task")
145+
return fmt.Errorf("creating task: %w", err)
147146

148147
}
149148
defer task.Delete(ctx)
150149

151150
log.Printf("Successfully created task: %s for the container\n", task.ID())
152151
exitStatusC, err := task.Wait(ctx)
153152
if err != nil {
154-
return errors.Wrapf(err, "waiting for task")
155-
153+
return fmt.Errorf("waiting for task: %w", err)
156154
}
157155

158156
log.Println("Completed waiting for the container task")
159157
if err := task.Start(ctx); err != nil {
160-
return errors.Wrapf(err, "starting task")
161-
158+
return fmt.Errorf("starting task: %w", err)
162159
}
163160

164161
log.Println("Successfully started the container task")
@@ -169,7 +166,7 @@ func taskWorkflow(containerCIDR, gateway, snapshotter string) (err error) {
169166
ip, _, err := net.ParseCIDR(containerCIDR)
170167
if err != nil {
171168
// this is validated as part of the CreateVM call, should never happen
172-
return errors.Wrapf(err, "failed parsing CIDR %q", containerCIDR)
169+
return fmt.Errorf("failed parsing CIDR %q: %w", containerCIDR, err)
173170
}
174171

175172
log.Println("Executing http GET on " + ip.String())
@@ -180,13 +177,13 @@ func taskWorkflow(containerCIDR, gateway, snapshotter string) (err error) {
180177
}
181178

182179
if err := task.Kill(ctx, syscall.SIGTERM); err != nil {
183-
return errors.Wrapf(err, "killing task")
180+
return fmt.Errorf("killing task: %w", err)
184181
}
185182

186183
status := <-exitStatusC
187184
code, _, err := status.Result()
188185
if err != nil {
189-
return errors.Wrapf(err, "getting task's exit code")
186+
return fmt.Errorf("getting task's exit code: %w", err)
190187
}
191188
log.Printf("task exited with status: %d\n", code)
192189

@@ -196,13 +193,13 @@ func taskWorkflow(containerCIDR, gateway, snapshotter string) (err error) {
196193
func getResponse(containerIP string) error {
197194
response, err := http.Get(fmt.Sprintf("http://%s/", containerIP))
198195
if err != nil {
199-
return errors.Wrapf(err, "Unable to get response from %s", containerIP)
196+
return fmt.Errorf("Unable to get response from %s: %w", containerIP, err)
200197
}
201198
defer response.Body.Close()
202199

203200
contents, err := ioutil.ReadAll(response.Body)
204201
if err != nil {
205-
return errors.Wrapf(err, "Unable to read response body from %s", containerIP)
202+
return fmt.Errorf("Unable to read response body from %s: %w", containerIP, err)
206203
}
207204

208205
log.Printf("Response from [%s]: \n[%s]\n", containerIP, contents)

firecracker-control/client/client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
package client
1515

1616
import (
17+
"fmt"
18+
1719
"github.com/containerd/containerd/pkg/ttrpcutil"
18-
"github.com/pkg/errors"
1920

2021
fccontrol "github.com/firecracker-microvm/firecracker-containerd/proto/service/fccontrol/ttrpc"
2122
)
@@ -31,7 +32,7 @@ type Client struct {
3132
func New(ttrpcAddress string) (*Client, error) {
3233
ttrpcClient, err := ttrpcutil.NewClient(ttrpcAddress)
3334
if err != nil {
34-
return nil, errors.Wrap(err, "failed to create ttrpc client")
35+
return nil, fmt.Errorf("failed to create ttrpc client: %w", err)
3536
}
3637

3738
client, err := ttrpcClient.Client()

0 commit comments

Comments
 (0)