Skip to content

Commit

Permalink
deps: remove deprecated github.com/pkg/errors
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Sep 27, 2023
1 parent 44d2128 commit 3577917
Show file tree
Hide file tree
Showing 39 changed files with 106 additions and 99 deletions.
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ linters:
enable:
- depguard
- errcheck
- errorlint
- gocritic
- gocyclo
- gofmt
Expand Down Expand Up @@ -40,6 +41,11 @@ linters-settings:
desc: 'compose-go uses yaml.v3'
gomodguard:
blocked:
modules:
- github.com/pkg/errors:
recommendations:
- errors
- fmt
versions:
- github.com/distribution/distribution:
reason: "use distribution/reference"
Expand Down
2 changes: 1 addition & 1 deletion cmd/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package compose

import (
"context"
"errors"
"fmt"
"os"
"os/signal"
Expand All @@ -37,7 +38,6 @@ import (
"github.com/docker/cli/cli/command"
"github.com/docker/compose/v2/pkg/remote"
"github.com/morikuni/aec"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down
2 changes: 1 addition & 1 deletion cmd/compose/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package compose

import (
"context"
"errors"
"fmt"
"sort"
"strings"
Expand All @@ -29,7 +30,6 @@ import (
"github.com/docker/cli/cli/command"
cliformatter "github.com/docker/cli/cli/command/formatter"
cliflags "github.com/docker/cli/cli/flags"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand Down
6 changes: 3 additions & 3 deletions cmd/compose/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ package compose

import (
"context"
"fmt"
"strconv"
"strings"

"github.com/docker/cli/cli/command"

"github.com/compose-spec/compose-go/types"
"github.com/pkg/errors"
"golang.org/x/exp/maps"

"github.com/docker/compose/v2/pkg/api"
Expand Down Expand Up @@ -95,12 +95,12 @@ func parseServicesReplicasArgs(args []string) (map[string]int, error) {
for _, arg := range args {
key, val, ok := strings.Cut(arg, "=")
if !ok || key == "" || val == "" {
return nil, errors.Errorf("invalid scale specifier: %s", arg)
return nil, fmt.Errorf("invalid scale specifier: %s", arg)
}
intValue, err := strconv.Atoi(val)

if err != nil {
return nil, errors.Errorf("invalid scale specifier: can't parse replica value as int: %v", arg)
return nil, fmt.Errorf("invalid scale specifier: can't parse replica value as int: %v", arg)
}
serviceReplicaTuples[key] = intValue
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/compose/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ func runWatch(ctx context.Context, dockerCli command.Cli, backend api.Service, w
// validation done -- ensure we have the lockfile for this project before doing work
l, err := locker.NewPidfile(project.Name)
if err != nil {
return fmt.Errorf("cannot take exclusive lock for project %q: %v", project.Name, err)
return fmt.Errorf("cannot take exclusive lock for project %q: %w", project.Name, err)
}
if err := l.Lock(); err != nil {
return fmt.Errorf("cannot take exclusive lock for project %q: %v", project.Name, err)
return fmt.Errorf("cannot take exclusive lock for project %q: %w", project.Name, err)
}

if !watchOpts.noUp {
Expand Down
4 changes: 1 addition & 3 deletions cmd/formatter/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"strings"

"github.com/docker/compose/v2/pkg/api"

"github.com/pkg/errors"
)

// Print prints formatted lists in different formats
Expand Down Expand Up @@ -67,7 +65,7 @@ func Print(toJSON interface{}, format string, outWriter io.Writer, writerFn func
_, _ = fmt.Fprintln(outWriter, outJSON)
}
default:
return errors.Wrapf(api.ErrParsingFailed, "format value %q could not be parsed", format)
return fmt.Errorf("format value %q could not be parsed: %w", format, api.ErrParsingFailed)
}
return nil
}
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ require (
github.com/morikuni/aec v1.0.0
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc5
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
Expand All @@ -46,13 +45,12 @@ require (
go.opentelemetry.io/otel/sdk v1.14.0
go.opentelemetry.io/otel/trace v1.14.0
go.uber.org/goleak v1.2.1
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1
golang.org/x/sync v0.3.0
google.golang.org/grpc v1.58.2
gotest.tools/v3 v3.5.1
)

require golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1

require (
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
Expand Down Expand Up @@ -132,6 +130,7 @@ require (
github.com/opencontainers/runc v1.1.7 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
Expand Down
6 changes: 3 additions & 3 deletions internal/sync/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"archive/tar"
"bytes"
"context"
"errors"
"fmt"
"io"
"io/fs"
Expand All @@ -30,7 +31,6 @@ import (
"strings"

"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"

"github.com/compose-spec/compose-go/types"
moby "github.com/docker/docker/api/types"
Expand Down Expand Up @@ -212,7 +212,7 @@ func (a *ArchiveBuilder) writeEntry(entry archiveEntry) error {
if useBuf {
a.copyBuf.Reset()
_, err = io.Copy(a.copyBuf, file)
if err != nil && err != io.EOF {
if err != nil && !errors.Is(err, io.EOF) {
return fmt.Errorf("copying %q: %w", pathInTar, err)
}
header.Size = int64(len(a.copyBuf.Bytes()))
Expand All @@ -232,7 +232,7 @@ func (a *ArchiveBuilder) writeEntry(entry archiveEntry) error {
_, err = io.Copy(a.tw, file)
}

if err != nil && err != io.EOF {
if err != nil && !errors.Is(err, io.EOF) {
return fmt.Errorf("copying %q: %w", pathInTar, err)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/sync/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package sync

import (
"context"
"errors"
"io"
"sync"
"testing"
"time"

"github.com/pkg/errors"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -115,7 +115,7 @@ func (b *bufReader) consume() {
b.data = append(b.data, buf[:n]...)
b.mu.Unlock()
}
if err == io.EOF {
if errors.Is(err, io.EOF) {
return
}
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions internal/tracing/docker_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func traceClientFromDockerContext(dockerCli command.Cli, otelEnv envMap) (otlptr
// automatic integration with Docker Desktop;
cfg, err := ConfigFromDockerContext(dockerCli.ContextStore(), dockerCli.CurrentContext())
if err != nil {
return nil, fmt.Errorf("loading otel config from docker context metadata: %v", err)
return nil, fmt.Errorf("loading otel config from docker context metadata: %w", err)
}

if cfg.Endpoint == "" {
Expand All @@ -52,13 +52,13 @@ func traceClientFromDockerContext(dockerCli command.Cli, otelEnv envMap) (otlptr
defer func() {
for k, v := range otelEnv {
if err := os.Setenv(k, v); err != nil {
panic(fmt.Errorf("restoring env for %q: %v", k, err))
panic(fmt.Errorf("restoring env for %q: %w", k, err))
}
}
}()
for k := range otelEnv {
if err := os.Unsetenv(k); err != nil {
return nil, fmt.Errorf("stashing env for %q: %v", k, err)
return nil, fmt.Errorf("stashing env for %q: %w", k, err)
}
}

Expand All @@ -71,7 +71,7 @@ func traceClientFromDockerContext(dockerCli command.Cli, otelEnv envMap) (otlptr
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
return nil, fmt.Errorf("initializing otel connection from docker context metadata: %v", err)
return nil, fmt.Errorf("initializing otel connection from docker context metadata: %w", err)
}

client := otlptracegrpc.NewClient(otlptracegrpc.WithGRPCConn(conn))
Expand Down
2 changes: 1 addition & 1 deletion internal/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func InitProvider(dockerCli command.Cli) (ShutdownFunc, error) {
),
)
if err != nil {
return nil, fmt.Errorf("failed to create resource: %v", err)
return nil, fmt.Errorf("failed to create resource: %w", err)
}

muxExporter := MuxExporter{exporters: exporters}
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/dryrunclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"crypto/rand"
"encoding/json"
"errors"
"fmt"
"io"
"net"
Expand All @@ -44,7 +45,6 @@ import (
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/jsonmessage"
specs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package api

import (
"github.com/pkg/errors"
"errors"
)

const (
Expand Down
11 changes: 6 additions & 5 deletions pkg/api/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,36 @@
package api

import (
"errors"
"fmt"
"testing"

"github.com/pkg/errors"
"gotest.tools/v3/assert"
)

func TestIsNotFound(t *testing.T) {
err := errors.Wrap(ErrNotFound, `object "name"`)
err := fmt.Errorf(`object "name": %w`, ErrNotFound)
assert.Assert(t, IsNotFoundError(err))

assert.Assert(t, !IsNotFoundError(errors.New("another error")))
}

func TestIsAlreadyExists(t *testing.T) {
err := errors.Wrap(ErrAlreadyExists, `object "name"`)
err := fmt.Errorf(`object "name": %w`, ErrAlreadyExists)
assert.Assert(t, IsAlreadyExistsError(err))

assert.Assert(t, !IsAlreadyExistsError(errors.New("another error")))
}

func TestIsForbidden(t *testing.T) {
err := errors.Wrap(ErrForbidden, `object "name"`)
err := fmt.Errorf(`object "name": %w`, ErrForbidden)
assert.Assert(t, IsForbiddenError(err))

assert.Assert(t, !IsForbiddenError(errors.New("another error")))
}

func TestIsUnknown(t *testing.T) {
err := errors.Wrap(ErrUnknown, `object "name"`)
err := fmt.Errorf(`object "name": %w`, ErrUnknown)
assert.Assert(t, IsUnknownError(err))

assert.Assert(t, !IsUnknownError(errors.New("another error")))
Expand Down
4 changes: 3 additions & 1 deletion pkg/compose/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package compose

import (
"context"
"errors"
"fmt"
"io"
"strings"
Expand Down Expand Up @@ -132,7 +133,8 @@ func (s *composeService) attachContainerStreams(ctx context.Context, container s
if streamIn != nil && stdin != nil {
go func() {
_, err := io.Copy(streamIn, stdin)
if _, ok := err.(term.EscapeError); ok {
var escapeErr term.EscapeError
if errors.As(err, &escapeErr) {
close(detached)
}
}()
Expand Down
Loading

0 comments on commit 3577917

Please sign in to comment.