1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-10-30 23:58:09 +02:00

refactor: replace pkg/errors.Wrap with fmt.Errorf (#1812)

* refactor: remove pkg/errors

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* refactor: remove pkg/errors

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker
2020-09-21 14:47:51 -03:00
committed by GitHub
parent ee540c6371
commit 65ffbf1921
24 changed files with 88 additions and 96 deletions

View File

@@ -8,7 +8,6 @@ import (
"github.com/fatih/color"
"github.com/goreleaser/goreleaser/internal/pipe/defaults"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@@ -39,7 +38,7 @@ func newCheckCmd() *checkCmd {
return defaults.Pipe{}.Run(ctx)
}); err != nil {
log.WithError(err).Error(color.New(color.Bold).Sprintf("config is invalid"))
return errors.Wrap(err, "invalid config")
return fmt.Errorf("invalid config: %w", err)
}
if ctx.Deprecated {

1
go.mod
View File

@@ -19,7 +19,6 @@ require (
github.com/mattn/go-shellwords v1.0.10
github.com/mattn/go-zglob v0.0.3
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.0.0
github.com/stretchr/testify v1.6.1
github.com/ulikunitz/xz v0.5.8

View File

@@ -16,7 +16,6 @@ import (
"sync"
"github.com/apex/log"
"github.com/pkg/errors"
)
// Type defines the type of an artifact.
@@ -101,7 +100,7 @@ func (a Artifact) Checksum(algorithm string) (string, error) {
log.Debugf("calculating checksum for %s", a.Path)
file, err := os.Open(a.Path)
if err != nil {
return "", errors.Wrap(err, "failed to checksum")
return "", fmt.Errorf("failed to checksum: %w", err)
}
defer file.Close()
var h hash.Hash
@@ -125,7 +124,7 @@ func (a Artifact) Checksum(algorithm string) (string, error) {
}
_, err = io.Copy(h, file)
if err != nil {
return "", errors.Wrap(err, "failed to checksum")
return "", fmt.Errorf("failed to checksum: %w", err)
}
return hex.EncodeToString(h.Sum(nil)), nil
}

View File

@@ -1,6 +1,7 @@
package golang
import (
"errors"
"fmt"
"go/ast"
"go/parser"
@@ -18,7 +19,6 @@ import (
api "github.com/goreleaser/goreleaser/pkg/build"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/pkg/errors"
)
// Default builder instance.
@@ -122,7 +122,7 @@ func (*Builder) Build(ctx *context.Context, build config.Build, options api.Opti
cmd = append(cmd, "-o", options.Path, build.Main)
if err := run(ctx, cmd, env, build.Dir); err != nil {
return errors.Wrapf(err, "failed to build for %s", options.Target)
return fmt.Errorf("failed to build for %s: %w", options.Target, err)
}
if build.ModTimestamp != "" {
@@ -137,7 +137,7 @@ func (*Builder) Build(ctx *context.Context, build config.Build, options api.Opti
modTime := time.Unix(modUnix, 0)
err = os.Chtimes(options.Path, modTime, modTime)
if err != nil {
return errors.Wrapf(err, "failed to change times for %s", options.Target)
return fmt.Errorf("failed to change times for %s: %w", options.Target, err)
}
}
@@ -225,7 +225,7 @@ func checkMain(build config.Build) error {
if stat.IsDir() {
packs, err := parser.ParseDir(token.NewFileSet(), main, nil, 0)
if err != nil {
return errors.Wrapf(err, "failed to parse dir: %s", main)
return fmt.Errorf("failed to parse dir: %s: %w", main, err)
}
for _, pack := range packs {
for _, file := range pack.Files {
@@ -238,7 +238,7 @@ func checkMain(build config.Build) error {
}
file, err := parser.ParseFile(token.NewFileSet(), main, nil, 0)
if err != nil {
return errors.Wrapf(err, "failed to parse file: %s", main)
return fmt.Errorf("failed to parse file: %s: %w", main, err)
}
if hasMain(file) {
return nil

View File

@@ -1,13 +1,13 @@
package extrafiles
import (
"fmt"
"os"
"path/filepath"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/mattn/go-zglob"
"github.com/pkg/errors"
)
// Find resolves extra files globs et al into a map of names/paths or an error.
@@ -17,7 +17,7 @@ func Find(files []config.ExtraFile) (map[string]string, error) {
if extra.Glob != "" {
files, err := zglob.Glob(extra.Glob)
if err != nil {
return result, errors.Wrapf(err, "globbing failed for pattern %s", extra.Glob)
return result, fmt.Errorf("globbing failed for pattern %s: %w", extra.Glob, err)
}
for _, file := range files {
info, err := os.Stat(file)

View File

@@ -1,11 +1,11 @@
package git
import (
"errors"
"fmt"
"strings"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/pkg/errors"
)
// ExtractRepoFromConfig gets the repo name from the Git config.

View File

@@ -12,8 +12,6 @@ import (
"strings"
"github.com/apex/log"
"github.com/pkg/errors"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/semerrgroup"
@@ -59,7 +57,7 @@ func assetOpenDefault(kind string, a *artifact.Artifact) (*asset, error) {
return nil, err
}
if s.IsDir() {
return nil, errors.Errorf("%s: upload failed: the asset to upload can't be a directory", kind)
return nil, fmt.Errorf("%s: upload failed: the asset to upload can't be a directory", kind)
}
return &asset{
ReadCloser: f,
@@ -221,7 +219,7 @@ func uploadAsset(ctx *context.Context, upload *config.Upload, artifact *artifact
if err != nil {
msg := fmt.Sprintf("%s: error while building the target url", kind)
log.WithField("instance", upload.Name).WithError(err).Error(msg)
return errors.Wrap(err, msg)
return fmt.Errorf("%s: %w", msg, err)
}
// Handle the artifact
@@ -257,7 +255,7 @@ func uploadAsset(ctx *context.Context, upload *config.Upload, artifact *artifact
"instance": upload.Name,
"username": username,
}).Error(msg)
return errors.Wrap(err, msg)
return fmt.Errorf("%s: %w", msg, err)
}
if err := res.Body.Close(); err != nil {
log.WithError(err).Warn("failed to close response body")

View File

@@ -3,6 +3,7 @@ package http
import (
"bytes"
"encoding/pem"
"errors"
"fmt"
"io/ioutil"
h "net/http"
@@ -16,7 +17,6 @@ import (
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
)
@@ -137,7 +137,7 @@ func checks(checks ...check) func(rs []*h.Request) error {
}
}
if !found {
return errors.Errorf("check not found for request %+v", r)
return fmt.Errorf("check not found for request %+v", r)
}
}
return nil
@@ -147,27 +147,27 @@ func checks(checks ...check) func(rs []*h.Request) error {
func doCheck(c check, r *h.Request) error {
contentLength := int64(len(c.content))
if r.ContentLength != contentLength {
return errors.Errorf("request content-length header value %v unexpected, wanted %v", r.ContentLength, contentLength)
return fmt.Errorf("request content-length header value %v unexpected, wanted %v", r.ContentLength, contentLength)
}
bs, err := ioutil.ReadAll(r.Body)
if err != nil {
return errors.Errorf("reading request body: %v", err)
return fmt.Errorf("reading request body: %v", err)
}
if !bytes.Equal(bs, c.content) {
return errors.New("content does not match")
}
if int64(len(bs)) != contentLength {
return errors.Errorf("request content length %v unexpected, wanted %v", int64(len(bs)), contentLength)
return fmt.Errorf("request content length %v unexpected, wanted %v", int64(len(bs)), contentLength)
}
if r.RequestURI != c.path {
return errors.Errorf("bad request uri %q, expecting %q", r.RequestURI, c.path)
return fmt.Errorf("bad request uri %q, expecting %q", r.RequestURI, c.path)
}
if u, p, ok := r.BasicAuth(); !ok || u != c.user || p != c.pass {
return errors.Errorf("bad basic auth credentials: %s/%s", u, p)
return fmt.Errorf("bad basic auth credentials: %s/%s", u, p)
}
for k, v := range c.headers {
if r.Header.Get(k) != v {
return errors.Errorf("bad header value for %s: expected %s, got %s", k, v, r.Header.Get(k))
return fmt.Errorf("bad header value for %s: expected %s, got %s", k, v, r.Header.Get(k))
}
}
return nil
@@ -203,7 +203,7 @@ func TestUpload(t *testing.T) {
if r.StatusCode/100 == 2 {
return nil
}
return errors.Errorf("unexpected http status code: %v", r.StatusCode)
return fmt.Errorf("unexpected http status code: %v", r.StatusCode)
}
ctx := context.New(config.Project{
ProjectName: "blah",

View File

@@ -13,7 +13,6 @@ import (
"github.com/apex/log"
"github.com/campoy/unique"
"github.com/mattn/go-zglob"
"github.com/pkg/errors"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/ids"
@@ -219,11 +218,11 @@ func findFiles(template *tmpl.Template, archive config.Archive) (result []string
for _, glob := range archive.Files {
replaced, err := template.Apply(glob)
if err != nil {
return result, errors.Wrapf(err, "failed to apply template %s", glob)
return result, fmt.Errorf("failed to apply template %s: %w", glob, err)
}
files, err := zglob.Glob(replaced)
if err != nil {
return result, errors.Wrapf(err, "globbing failed for pattern %s", glob)
return result, fmt.Errorf("globbing failed for pattern %s: %w", glob, err)
}
result = append(result, files...)
}

View File

@@ -14,7 +14,6 @@ import (
"github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/pkg/errors"
"gocloud.dev/blob"
"gocloud.dev/secrets"
@@ -141,21 +140,21 @@ func uploadData(ctx *context.Context, conf config.Blob, up uploader, dataFile, u
func handleError(err error, url string) error {
switch {
case errorContains(err, "NoSuchBucket", "ContainerNotFound", "notFound"):
return errors.Wrapf(err, "provided bucket does not exist: %s", url)
return fmt.Errorf("provided bucket does not exist: %s: %w", url, err)
case errorContains(err, "NoCredentialProviders"):
return errors.Wrapf(err, "check credentials and access to bucket: %s", url)
return fmt.Errorf("check credentials and access to bucket: %s: %w", url, err)
case errorContains(err, "InvalidAccessKeyId"):
return errors.Wrap(err, "aws access key id you provided does not exist in our records")
return fmt.Errorf("aws access key id you provided does not exist in our records: %w", err)
case errorContains(err, "AuthenticationFailed"):
return errors.Wrap(err, "azure storage key you provided is not valid")
return fmt.Errorf("azure storage key you provided is not valid: %w", err)
case errorContains(err, "invalid_grant"):
return errors.Wrap(err, "google app credentials you provided is not valid")
return fmt.Errorf("google app credentials you provided is not valid: %w", err)
case errorContains(err, "no such host"):
return errors.Wrap(err, "azure storage account you provided is not valid")
return fmt.Errorf("azure storage account you provided is not valid: %w", err)
case errorContains(err, "ServiceCode=ResourceNotFound"):
return errors.Wrapf(err, "missing azure storage key for provided bucket %s", url)
return fmt.Errorf("missing azure storage key for provided bucket %s: %w", url, err)
default:
return errors.Wrap(err, "failed to write to bucket")
return fmt.Errorf("failed to write to bucket: %w", err)
}
}
@@ -169,19 +168,19 @@ func newUploader(ctx *context.Context) uploader {
func getData(ctx *context.Context, conf config.Blob, path string) ([]byte, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return data, errors.Wrapf(err, "failed to open file %s", path)
return data, fmt.Errorf("failed to open file %s: %w", path, err)
}
if conf.KMSKey == "" {
return data, nil
}
keeper, err := secrets.OpenKeeper(ctx, conf.KMSKey)
if err != nil {
return data, errors.Wrapf(err, "failed to open kms %s", conf.KMSKey)
return data, fmt.Errorf("failed to open kms %s: %w", conf.KMSKey, err)
}
defer keeper.Close()
data, err = keeper.Encrypt(ctx, data)
if err != nil {
return data, errors.Wrap(err, "failed to encrypt with kms")
return data, fmt.Errorf("failed to encrypt with kms: %w", err)
}
return data, err
}

View File

@@ -2,6 +2,7 @@ package brew
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"path"
@@ -17,7 +18,6 @@ import (
"github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/pkg/errors"
)
// ErrNoArchivesFound happens when 0 archives are found.
@@ -204,7 +204,7 @@ func doRun(ctx *context.Context, brew config.Homebrew, cl client.Client) error {
var path = filepath.Join(ctx.Config.Dist, filename)
log.WithField("formula", path).Info("writing")
if err := ioutil.WriteFile(path, []byte(content), 0644); err != nil { //nolint: gosec
return errors.Wrap(err, "failed to write brew formula")
return fmt.Errorf("failed to write brew formula: %w", err)
}
if strings.TrimSpace(brew.SkipUpload) == "true" {

View File

@@ -20,7 +20,6 @@ import (
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/mattn/go-shellwords"
"github.com/pkg/errors"
// langs to init.
_ "github.com/goreleaser/goreleaser/internal/builders/golang"
@@ -91,14 +90,14 @@ func runPipeOnBuild(ctx *context.Context, build config.Build) error {
}
if err := runHook(ctx, *opts, build.Env, build.Hooks.Pre); err != nil {
return errors.Wrap(err, "pre hook failed")
return fmt.Errorf("pre hook failed: %w", err)
}
if err := doBuild(ctx, build, *opts); err != nil {
return err
}
if !ctx.SkipPostBuildHooks {
if err := runHook(ctx, *opts, build.Env, build.Hooks.Post); err != nil {
return errors.Wrap(err, "post hook failed")
return fmt.Errorf("post hook failed: %w", err)
}
}
return nil
@@ -229,7 +228,7 @@ func run(ctx *context.Context, dir string, command, env []string) error {
entry.WithField("env", env).Debug("running")
if err := cmd.Run(); err != nil {
entry.WithError(err).Debug("failed")
return errors.Wrapf(err, "%q", b.String())
return fmt.Errorf("%q: %w", b.String(), err)
}
return nil
}

View File

@@ -2,6 +2,7 @@
package docker
import (
"errors"
"fmt"
"io/ioutil"
"os"
@@ -16,7 +17,6 @@ import (
"github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/pkg/errors"
)
// ErrNoDocker is shown when docker cannot be found in $PATH.
@@ -97,7 +97,7 @@ func doRun(ctx *context.Context) error {
for i := range docker.Binaries {
bin, err := tmpl.New(ctx).Apply(docker.Binaries[i])
if err != nil {
return errors.Wrapf(err, "failed to execute binary template '%s'", docker.Binaries[i])
return fmt.Errorf("failed to execute binary template '%s': %w", docker.Binaries[i], err)
}
binaryNames[i] = bin
}
@@ -139,7 +139,7 @@ func doRun(ctx *context.Context) error {
func process(ctx *context.Context, docker config.Docker, bins []*artifact.Artifact) error {
tmp, err := ioutil.TempDir(ctx.Config.Dist, "goreleaserdocker")
if err != nil {
return errors.Wrap(err, "failed to create temporary dir")
return fmt.Errorf("failed to create temporary dir: %w", err)
}
log.Debug("tempdir: " + tmp)
@@ -149,19 +149,19 @@ func process(ctx *context.Context, docker config.Docker, bins []*artifact.Artifa
}
if err := os.Link(docker.Dockerfile, filepath.Join(tmp, "Dockerfile")); err != nil {
return errors.Wrap(err, "failed to link dockerfile")
return fmt.Errorf("failed to link dockerfile: %w", err)
}
for _, file := range docker.Files {
if err := os.MkdirAll(filepath.Join(tmp, filepath.Dir(file)), 0755); err != nil {
return errors.Wrapf(err, "failed to link extra file '%s'", file)
return fmt.Errorf("failed to link extra file '%s': %w", file, err)
}
if err := link(file, filepath.Join(tmp, file)); err != nil {
return errors.Wrapf(err, "failed to link extra file '%s'", file)
return fmt.Errorf("failed to link extra file '%s': %w", file, err)
}
}
for _, bin := range bins {
if err := os.Link(bin.Path, filepath.Join(tmp, filepath.Base(bin.Path))); err != nil {
return errors.Wrap(err, "failed to link binary")
return fmt.Errorf("failed to link binary: %w", err)
}
}
@@ -205,7 +205,7 @@ func processImageTemplates(ctx *context.Context, docker config.Docker) ([]string
for _, imageTemplate := range docker.ImageTemplates {
image, err := tmpl.New(ctx).Apply(imageTemplate)
if err != nil {
return nil, errors.Wrapf(err, "failed to execute image template '%s'", imageTemplate)
return nil, fmt.Errorf("failed to execute image template '%s': %w", imageTemplate, err)
}
images = append(images, image)
@@ -220,7 +220,7 @@ func processBuildFlagTemplates(ctx *context.Context, docker config.Docker) ([]st
for _, buildFlagTemplate := range docker.BuildFlagTemplates {
buildFlag, err := tmpl.New(ctx).Apply(buildFlagTemplate)
if err != nil {
return nil, errors.Wrapf(err, "failed to process build flag template '%s'", buildFlagTemplate)
return nil, fmt.Errorf("failed to process build flag template '%s': %w", buildFlagTemplate, err)
}
buildFlags = append(buildFlags, buildFlag)
}
@@ -258,7 +258,7 @@ func dockerBuild(ctx *context.Context, root string, images, flags []string) erro
log.WithField("cmd", cmd.Args).WithField("cwd", cmd.Dir).Debug("running")
out, err := cmd.CombinedOutput()
if err != nil {
return errors.Wrapf(err, "failed to build docker image: %s: \n%s", images[0], string(out))
return fmt.Errorf("failed to build docker image: %s: \n%s: %w", images[0], string(out), err)
}
log.Debugf("docker build output: \n%s", string(out))
return nil
@@ -280,7 +280,7 @@ func dockerPush(ctx *context.Context, image *artifact.Artifact) error {
log.WithField("cmd", cmd.Args).Debug("running")
out, err := cmd.CombinedOutput()
if err != nil {
return errors.Wrapf(err, "failed to push docker image: \n%s", string(out))
return fmt.Errorf("failed to push docker image: \n%s: %w", string(out), err)
}
log.Debugf("docker push output: \n%s", string(out))
ctx.Artifacts.Add(&artifact.Artifact{

View File

@@ -4,12 +4,13 @@ package env
import (
"bufio"
"errors"
"fmt"
"os"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/pkg/context"
homedir "github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
)
// ErrMissingToken indicates an error when GITHUB_TOKEN, GITLAB_TOKEN and GITEA_TOKEN are all missing in the environment.
@@ -98,15 +99,15 @@ func checkErrors(ctx *context.Context, noTokens, noTokenErrs bool, gitlabTokenEr
}
if gitlabTokenErr != nil {
return errors.Wrap(gitlabTokenErr, "failed to load gitlab token")
return fmt.Errorf("failed to load gitlab token: %w", gitlabTokenErr)
}
if githubTokenErr != nil {
return errors.Wrap(githubTokenErr, "failed to load github token")
return fmt.Errorf("failed to load github token: %w", githubTokenErr)
}
if giteaTokenErr != nil {
return errors.Wrap(giteaTokenErr, "failed to load gitea token")
return fmt.Errorf("failed to load gitea token: %w", giteaTokenErr)
}
return nil
}

View File

@@ -1,6 +1,7 @@
package git
import (
"fmt"
"os"
"os/exec"
"strconv"
@@ -8,7 +9,6 @@ import (
"time"
"github.com/apex/log"
"github.com/pkg/errors"
"github.com/goreleaser/goreleaser/internal/git"
"github.com/goreleaser/goreleaser/internal/pipe"
@@ -67,19 +67,19 @@ func getInfo(ctx *context.Context) (context.GitInfo, error) {
func getGitInfo() (context.GitInfo, error) {
short, err := getShortCommit()
if err != nil {
return context.GitInfo{}, errors.Wrap(err, "couldn't get current commit")
return context.GitInfo{}, fmt.Errorf("couldn't get current commit: %w", err)
}
full, err := getFullCommit()
if err != nil {
return context.GitInfo{}, errors.Wrap(err, "couldn't get current commit")
return context.GitInfo{}, fmt.Errorf("couldn't get current commit: %w", err)
}
date, err := getCommitDate()
if err != nil {
return context.GitInfo{}, errors.Wrap(err, "couldn't get commit date")
return context.GitInfo{}, fmt.Errorf("couldn't get commit date: %w", err)
}
url, err := getURL()
if err != nil {
return context.GitInfo{}, errors.Wrap(err, "couldn't get remote URL")
return context.GitInfo{}, fmt.Errorf("couldn't get remote URL: %w", err)
}
tag, err := getTag()
if err != nil {

View File

@@ -12,7 +12,6 @@ import (
_ "github.com/goreleaser/nfpm/deb" // blank import to register the format
_ "github.com/goreleaser/nfpm/rpm" // blank import to register the format
"github.com/imdario/mergo"
"github.com/pkg/errors"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/ids"
@@ -178,7 +177,7 @@ func create(ctx *context.Context, fpm config.NFPM, format, arch string, binaries
}
if err = nfpm.Validate(info); err != nil {
return errors.Wrap(err, "invalid nfpm config")
return fmt.Errorf("invalid nfpm config: %w", err)
}
packager, err := nfpm.Get(format)
@@ -194,10 +193,10 @@ func create(ctx *context.Context, fpm config.NFPM, format, arch string, binaries
}
defer w.Close()
if err := packager.Package(nfpm.WithDefaults(info), w); err != nil {
return errors.Wrap(err, "nfpm failed")
return fmt.Errorf("nfpm failed: %w", err)
}
if err := w.Close(); err != nil {
return errors.Wrap(err, "could not close package file")
return fmt.Errorf("could not close package file: %w", err)
}
ctx.Artifacts.Add(&artifact.Artifact{
Type: artifact.LinuxPackage,

View File

@@ -16,7 +16,6 @@ import (
"github.com/goreleaser/goreleaser/internal/pipe/snapcraft"
"github.com/goreleaser/goreleaser/internal/pipe/upload"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/pkg/errors"
)
// Pipe that publishes artifacts.
@@ -58,7 +57,7 @@ func (Pipe) Run(ctx *context.Context) error {
middleware.ErrHandler(publisher.Publish),
middleware.ExtraPadding,
)(ctx); err != nil {
return errors.Wrapf(err, "%s: failed to publish artifacts", publisher.String())
return fmt.Errorf("%s: failed to publish artifacts: %w", publisher.String(), err)
}
}
return nil

View File

@@ -1,6 +1,8 @@
package release
import (
"errors"
"fmt"
"os"
"time"
@@ -12,7 +14,6 @@ import (
"github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/semerrgroup"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/pkg/errors"
)
// ErrMultipleReleases indicates that multiple releases are defined. ATM only one of them is allowed.
@@ -133,7 +134,7 @@ func doPublish(ctx *context.Context, client client.Client) error {
for name, path := range extraFiles {
if _, err := os.Stat(path); os.IsNotExist(err) {
return errors.Wrapf(err, "failed to upload %s", name)
return fmt.Errorf("failed to upload %s: %w", name, err)
}
ctx.Artifacts.Add(&artifact.Artifact{
Name: name,
@@ -203,5 +204,5 @@ loop:
}
}
return errors.Wrapf(err, "failed to upload %s after %d tries", artifact.Name, try)
return fmt.Errorf("failed to upload %s after %d tries: %w", artifact.Name, try, err)
}

View File

@@ -1,6 +1,8 @@
package release
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
@@ -13,7 +15,6 @@ import (
"github.com/goreleaser/goreleaser/internal/testlib"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
@@ -567,7 +568,7 @@ func (c *DummyClient) Upload(ctx *context.Context, releaseID string, artifact *a
// ensure file is read to better mimic real behavior
_, err := ioutil.ReadAll(file)
if err != nil {
return errors.Wrapf(err, "unexpected error")
return fmt.Errorf("unexpected error: %w", err)
}
if c.FailToUpload {
return errors.New("upload failed")

View File

@@ -1,11 +1,12 @@
package semver
import (
"fmt"
"github.com/Masterminds/semver/v3"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/pkg/errors"
)
// Pipe is a global hook pipe.
@@ -29,7 +30,7 @@ func (Pipe) Run(ctx *context.Context) error {
Warn("current tag is not a semantic tag")
return pipe.ErrSkipValidateEnabled
}
return errors.Wrapf(err, "failed to parse tag %s as semver", ctx.Git.CurrentTag)
return fmt.Errorf("failed to parse tag %s as semver: %w", ctx.Git.CurrentTag, err)
}
ctx.Semver = context.Semver{
Major: sv.Major(),

View File

@@ -15,7 +15,6 @@ import (
"github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/pkg/errors"
)
// Pipe for artifact signing.
@@ -116,7 +115,7 @@ func signone(ctx *context.Context, cfg config.Sign, a *artifact.Artifact) (*arti
var arg = expand(a, env)
arg, err := tmpl.New(ctx).WithEnv(env).Apply(arg)
if err != nil {
return nil, errors.Wrapf(err, "sign failed: %s: invalid template", a)
return nil, fmt.Errorf("sign failed: %s: invalid template: %w", a, err)
}
args = append(args, arg)
}

View File

@@ -2,6 +2,7 @@
package snapcraft
import (
"errors"
"fmt"
"io/ioutil"
"os"
@@ -10,7 +11,6 @@ import (
"strings"
"github.com/apex/log"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"
"github.com/goreleaser/goreleaser/internal/artifact"
@@ -181,10 +181,10 @@ func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries [
file.Mode = 0644
}
if err := os.MkdirAll(filepath.Join(primeDir, filepath.Dir(file.Destination)), 0755); err != nil {
return errors.Wrapf(err, "failed to link extra file '%s'", file.Source)
return fmt.Errorf("failed to link extra file '%s': %w", file.Source, err)
}
if err := link(file.Source, filepath.Join(primeDir, file.Destination), os.FileMode(file.Mode)); err != nil {
return errors.Wrapf(err, "failed to link extra file '%s'", file.Source)
return fmt.Errorf("failed to link extra file '%s': %w", file.Source, err)
}
}
@@ -234,10 +234,10 @@ func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries [
Debug("linking")
if err = os.Link(binary.Path, destBinaryPath); err != nil {
return errors.Wrap(err, "failed to link binary")
return fmt.Errorf("failed to link binary: %w", err)
}
if err := os.Chmod(destBinaryPath, 0555); err != nil {
return errors.Wrap(err, "failed to change binary permissions")
return fmt.Errorf("failed to change binary permissions: %w", err)
}
}
@@ -262,16 +262,16 @@ func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries [
if config.Completer != "" {
destCompleterPath := filepath.Join(primeDir, config.Completer)
if err := os.MkdirAll(filepath.Dir(destCompleterPath), 0755); err != nil {
return errors.Wrapf(err, "failed to create folder")
return fmt.Errorf("failed to create folder: %w", err)
}
log.WithField("src", config.Completer).
WithField("dst", destCompleterPath).
Debug("linking")
if err := os.Link(config.Completer, destCompleterPath); err != nil {
return errors.Wrap(err, "failed to link completer")
return fmt.Errorf("failed to link completer: %w", err)
}
if err := os.Chmod(destCompleterPath, 0644); err != nil {
return errors.Wrap(err, "failed to change completer permissions")
return fmt.Errorf("failed to change completer permissions: %w", err)
}
appMetadata.Completer = config.Completer
}

View File

@@ -7,7 +7,6 @@ import (
"github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/pkg/errors"
)
// Pipe for checksums.
@@ -31,7 +30,7 @@ func (Pipe) Run(ctx *context.Context) error {
}
name, err := tmpl.New(ctx).Apply(ctx.Config.Snapshot.NameTemplate)
if err != nil {
return errors.Wrap(err, "failed to generate snapshot name")
return fmt.Errorf("failed to generate snapshot name: %w", err)
}
if name == "" {
return fmt.Errorf("empty snapshot name")

View File

@@ -2,12 +2,12 @@
package upload
import (
"fmt"
h "net/http"
"github.com/goreleaser/goreleaser/internal/http"
"github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/pkg/errors"
)
// Pipe for http publishing.
@@ -40,7 +40,7 @@ func (Pipe) Publish(ctx *context.Context) error {
return http.Upload(ctx, ctx.Config.Uploads, "upload", func(res *h.Response) error {
if c := res.StatusCode; c < 200 || 299 < c {
return errors.Errorf("unexpected http response status: %s", res.Status)
return fmt.Errorf("unexpected http response status: %s", res.Status)
}
return nil
})