Skip to content

Commit

Permalink
replace pkg/errors and bump related library
Browse files Browse the repository at this point in the history
Signed-off-by: Zou Nengren <zouyee1989@gmail.com>
  • Loading branch information
zounengren committed Sep 22, 2021
1 parent be31719 commit c07e57c
Show file tree
Hide file tree
Showing 193 changed files with 11,806 additions and 2,556 deletions.
2 changes: 1 addition & 1 deletion cmd/ctd-decoder/enc_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ package main

import (
b64 "encoding/base64"
"errors"
"io/ioutil"
"os"
"path/filepath"
"strings"

encconfig "github.com/containers/ocicrypt/config"
cryptUtils "github.com/containers/ocicrypt/utils"
"github.com/pkg/errors"
)

// getDecryptionKeys reads the keys from the given directory
Expand Down
16 changes: 8 additions & 8 deletions cmd/ctd-decoder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"github.com/containerd/imgcrypt"
"github.com/containerd/imgcrypt/images/encryption"
"github.com/containerd/typeurl"

"github.com/gogo/protobuf/proto"
"github.com/gogo/protobuf/types"
"github.com/pkg/errors"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -72,14 +72,14 @@ func decrypt(ctx *cli.Context) error {
if ctx.GlobalIsSet("decryption-keys-path") {
keyPathCc, err := getDecryptionKeys(ctx.GlobalString("decryption-keys-path"))
if err != nil {
return errors.Wrap(err, "Unable to get decryption keys in provided key path")
return fmt.Errorf("unable to get decryption keys in provided key path: %w", err)
}
decCc = combineDecryptionConfigs(keyPathCc.DecryptConfig, &payload.DecryptConfig)
}

_, r, _, err := encryption.DecryptLayer(decCc, os.Stdin, payload.Descriptor, false)
if err != nil {
return errors.Wrapf(err, "call to DecryptLayer failed")
return fmt.Errorf("call to DecryptLayer failed: %w", err)
}

for {
Expand All @@ -88,7 +88,7 @@ func decrypt(ctx *cli.Context) error {
if err == io.EOF {
break
}
return errors.Wrapf(err, "could not copy data")
return fmt.Errorf("could not copy data: %w", err)
}
}
return nil
Expand All @@ -97,19 +97,19 @@ func decrypt(ctx *cli.Context) error {
func getPayload() (*imgcrypt.Payload, error) {
data, err := readPayload()
if err != nil {
return nil, errors.Wrap(err, "read payload")
return nil, fmt.Errorf("read payload: %w", err)
}
var any types.Any
if err := proto.Unmarshal(data, &any); err != nil {
return nil, errors.Wrapf(err, "could not proto.Unmarshal() decrypt data")
return nil, fmt.Errorf("could not proto.Unmarshal() decrypt data: %w", err)
}
v, err := typeurl.UnmarshalAny(&any)
if err != nil {
return nil, errors.Wrapf(err, "could not UnmarshalAny() the decrypt data")
return nil, fmt.Errorf("could not UnmarshalAny() the decrypt data: %w", err)
}
l, ok := v.(*imgcrypt.Payload)
if !ok {
return nil, errors.Errorf("unknown payload type %s", any.TypeUrl)
return nil, fmt.Errorf("unknown payload type %s", any.TypeUrl)
}
return l, nil
}
4 changes: 2 additions & 2 deletions cmd/ctd-decoder/main_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
package main

import (
"fmt"
"io/ioutil"
"os"

winio "github.com/Microsoft/go-winio"
"github.com/pkg/errors"
)

func readPayload() ([]byte, error) {
path := os.Getenv("STREAM_PROCESSOR_PIPE")

conn, err := winio.DialPipe(path, nil)
if err != nil {
return nil, errors.Wrapf(err, "could not DialPipe")
return nil, fmt.Errorf("could not DialPipe: %w", err)
}
defer conn.Close()
return ioutil.ReadAll(conn)
Expand Down
5 changes: 3 additions & 2 deletions cmd/ctr/commands/containers/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
package containers

import (
"errors"
"fmt"

"github.com/containerd/containerd"
"github.com/containerd/containerd/cmd/ctr/commands"
"github.com/containerd/containerd/errdefs"
"github.com/pkg/errors"

"github.com/urfave/cli"
)

Expand Down Expand Up @@ -88,7 +89,7 @@ var checkpointCommand = cli.Command{
}
defer func() {
if err := task.Resume(ctx); err != nil {
fmt.Println(errors.Wrap(err, "error resuming task"))
fmt.Println(fmt.Errorf("error resuming task: %w", err))
}
}()
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/ctr/commands/containers/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/containerd/imgcrypt/cmd/ctr/commands/flags"
"github.com/containerd/imgcrypt/cmd/ctr/commands/run"
"github.com/containerd/typeurl"
"github.com/pkg/errors"

"github.com/urfave/cli"
)

Expand Down Expand Up @@ -67,17 +67,17 @@ var createCommand = cli.Command{
if config {
id = context.Args().First()
if context.NArg() > 1 {
return errors.Wrap(errdefs.ErrInvalidArgument, "with spec config file, only container id should be provided")
return fmt.Errorf("with spec config file, only container id should be provided: %w", errdefs.ErrInvalidArgument)
}
} else {
id = context.Args().Get(1)
ref = context.Args().First()
if ref == "" {
return errors.Wrap(errdefs.ErrInvalidArgument, "image ref must be provided")
return fmt.Errorf("image ref must be provided: %w", errdefs.ErrInvalidArgument)
}
}
if id == "" {
return errors.Wrap(errdefs.ErrInvalidArgument, "container id must be provided")
return fmt.Errorf("container id must be provided: %w", errdefs.ErrInvalidArgument)
}
client, ctx, cancel, err := commands.NewClient(context)
if err != nil {
Expand Down Expand Up @@ -170,7 +170,7 @@ var deleteCommand = cli.Command{
}

if context.NArg() == 0 {
return errors.Wrap(errdefs.ErrInvalidArgument, "must specify at least one container to delete")
return fmt.Errorf("must specify at least one container to delete: %w", errdefs.ErrInvalidArgument)
}
for _, arg := range context.Args() {
if err := deleteContainer(ctx, client, arg, deleteOpts...); err != nil {
Expand Down Expand Up @@ -216,7 +216,7 @@ var setLabelsCommand = cli.Command{
Action: func(context *cli.Context) error {
containerID, labels := commands.ObjectWithLabelArgs(context)
if containerID == "" {
return errors.Wrap(errdefs.ErrInvalidArgument, "container id must be provided")
return fmt.Errorf("container id must be provided: %w", errdefs.ErrInvalidArgument)
}
client, ctx, cancel, err := commands.NewClient(context)
if err != nil {
Expand Down Expand Up @@ -258,7 +258,7 @@ var infoCommand = cli.Command{
Action: func(context *cli.Context) error {
id := context.Args().First()
if id == "" {
return errors.Wrap(errdefs.ErrInvalidArgument, "container id must be provided")
return fmt.Errorf("container id must be provided: %w", errdefs.ErrInvalidArgument)
}
client, ctx, cancel, err := commands.NewClient(context)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion cmd/ctr/commands/containers/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package containers

import (
"errors"

"github.com/containerd/containerd"
"github.com/containerd/containerd/cio"
"github.com/containerd/containerd/cmd/ctr/commands"
"github.com/containerd/containerd/errdefs"
"github.com/pkg/errors"

"github.com/urfave/cli"
)

Expand Down
3 changes: 2 additions & 1 deletion cmd/ctr/commands/images/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
package images

import (
"errors"
"fmt"

"github.com/containerd/containerd/cmd/ctr/commands"
"github.com/containerd/imgcrypt/cmd/ctr/commands/flags"
imgenc "github.com/containerd/imgcrypt/images/encryption"
"github.com/pkg/errors"

"github.com/urfave/cli"
)

Expand Down
3 changes: 2 additions & 1 deletion cmd/ctr/commands/images/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
package images

import (
"errors"
"fmt"

"github.com/containerd/containerd/cmd/ctr/commands"
"github.com/containerd/imgcrypt/cmd/ctr/commands/flags"
"github.com/pkg/errors"

"github.com/urfave/cli"
)

Expand Down
6 changes: 4 additions & 2 deletions cmd/ctr/commands/images/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
package images

import (
"errors"
"fmt"
"io"
"os"

"github.com/containerd/containerd/cmd/ctr/commands"
"github.com/containerd/containerd/images/archive"
"github.com/containerd/containerd/platforms"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -73,7 +75,7 @@ When '--all-platforms' is given all images in a manifest list must be available.
for _, ps := range pss {
p, err := platforms.Parse(ps)
if err != nil {
return errors.Wrapf(err, "invalid platform %q", ps)
return fmt.Errorf("invalid platform %q: %w", ps, err)
}
all = append(all, p)
}
Expand Down
13 changes: 7 additions & 6 deletions cmd/ctr/commands/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package images

import (
"errors"
"fmt"
"os"
"sort"
Expand All @@ -29,7 +30,7 @@ import (
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/pkg/progress"
"github.com/containerd/containerd/platforms"
"github.com/pkg/errors"

"github.com/urfave/cli"
)

Expand Down Expand Up @@ -84,7 +85,7 @@ var listCommand = cli.Command{
)
imageList, err := imageStore.List(ctx, filters...)
if err != nil {
return errors.Wrap(err, "failed to list images")
return fmt.Errorf("failed to list images: %w", err)
}
if quiet {
for _, image := range imageList {
Expand Down Expand Up @@ -223,7 +224,7 @@ var checkCommand = cli.Command{
args := []string(context.Args())
imageList, err := client.ListImages(ctx, args...)
if err != nil {
return errors.Wrap(err, "failed listing images")
return fmt.Errorf("failed listing images: %w", err)
}

for _, image := range imageList {
Expand All @@ -237,7 +238,7 @@ var checkCommand = cli.Command{
available, required, present, missing, err := images.Check(ctx, contentStore, image.Target(), platforms.Default())
if err != nil {
if exitErr == nil {
exitErr = errors.Wrapf(err, "unable to check %v", image.Name())
exitErr = fmt.Errorf("unable to check %v: %w", image.Name(), err)
}
log.G(ctx).WithError(err).Errorf("unable to check %v", image.Name())
status = "error"
Expand Down Expand Up @@ -270,7 +271,7 @@ var checkCommand = cli.Command{
unpacked, err := image.IsUnpacked(ctx, context.String("snapshotter"))
if err != nil {
if exitErr == nil {
exitErr = errors.Wrapf(err, "unable to check unpack for %v", image.Name())
exitErr = fmt.Errorf("unable to check unpack for %v: %w", image.Name(), err)
}
log.G(ctx).WithError(err).Errorf("unable to check unpack for %v", image.Name())
}
Expand Down Expand Up @@ -319,7 +320,7 @@ var removeCommand = cli.Command{
if err := imageStore.Delete(ctx, target, opts...); err != nil {
if !errdefs.IsNotFound(err) {
if exitErr == nil {
exitErr = errors.Wrapf(err, "unable to delete %v", target)
exitErr = fmt.Errorf("unable to delete %v: %w", target, err)
}
log.G(ctx).WithError(err).Errorf("unable to delete %v", target)
continue
Expand Down
2 changes: 1 addition & 1 deletion cmd/ctr/commands/images/layerinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package images

import (
"errors"
"fmt"
"os"
"sort"
Expand All @@ -27,7 +28,6 @@ import (
"github.com/containerd/containerd/platforms"
"github.com/containers/ocicrypt"

"github.com/pkg/errors"
"github.com/urfave/cli"
)

Expand Down
6 changes: 3 additions & 3 deletions cmd/ctr/commands/images/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
"github.com/containerd/containerd/leases"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/platforms"

"github.com/opencontainers/image-spec/identity"
"github.com/pkg/errors"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -93,7 +93,7 @@ When you are done, use the unmount command.
ps := context.String("platform")
p, err := platforms.Parse(ps)
if err != nil {
return errors.Wrapf(err, "unable to parse platform %s", ps)
return fmt.Errorf("unable to parse platform %s: %w", ps, err)
}

img, err := client.ImageService().Get(ctx, ref)
Expand All @@ -103,7 +103,7 @@ When you are done, use the unmount command.

i := containerd.NewImageWithPlatform(client, img, platforms.Only(p))
if err := i.Unpack(ctx, snapshotter); err != nil {
return errors.Wrap(err, "error unpacking image")
return fmt.Errorf("error unpacking image: %w", err)
}

diffIDs, err := i.RootFS(ctx)
Expand Down
Loading

0 comments on commit c07e57c

Please sign in to comment.