Repository: goreleaser/nfpm
Pull request #226 (2020-09-17 19:22:08)

refactor: remove pkg/errors
replace usages of `errors.Wrap` with `fmt.Errorf` using the new `%w` thing.

vercel[bot]: This pull request is being automatically deployed with Vercel ([learn more](https://vercel.link/github-learn-more)).  
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: [https://vercel.com/goreleaser/nfpm/9eadtf898](https://vercel.com/goreleaser/nfpm/9eadtf898)  
✅ Preview: [https://nfpm-git-err.goreleaser.vercel.app](https://nfpm-git-err.goreleaser.vercel.app)


codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/226?src=pr&el=h1) Report
> Merging [#226](https://codecov.io/gh/goreleaser/nfpm/pull/226?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/nfpm/commit/1666d2e168837d92131556e4c082a5ef21c491e8?el=desc) will **decrease** coverage by `0.09%`.
> The diff coverage is `18.64%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/nfpm/pull/226/graphs/tree.svg?width=650&height=150&src=pr&token=9QKGIxn7wg)](https://codecov.io/gh/goreleaser/nfpm/pull/226?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #226      +/-   ##
==========================================
- Coverage   66.43%   66.33%   -0.10%     
==========================================
  Files           9        9              
  Lines        1004     1007       +3     
==========================================
+ Hits          667      668       +1     
- Misses        202      204       +2     
  Partials      135      135              
```


| [Impacted Files](https://codecov.io/gh/goreleaser/nfpm/pull/226?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [apk/apk.go](https://codecov.io/gh/goreleaser/nfpm/pull/226/diff?src=pr&el=tree#diff-YXBrL2Fway5nbw==) | `66.52% <0.00%> (ø)` | |
| [nfpm.go](https://codecov.io/gh/goreleaser/nfpm/pull/226/diff?src=pr&el=tree#diff-bmZwbS5nbw==) | `78.04% <0.00%> (ø)` | |
| [rpm/rpm.go](https://codecov.io/gh/goreleaser/nfpm/pull/226/diff?src=pr&el=tree#diff-cnBtL3JwbS5nbw==) | `71.85% <0.00%> (ø)` | |
| [deb/deb.go](https://codecov.io/gh/goreleaser/nfpm/pull/226/diff?src=pr&el=tree#diff-ZGViL2RlYi5nbw==) | `66.78% <4.54%> (-0.36%)` | :arrow_down: |
| [internal/sign/rsa.go](https://codecov.io/gh/goreleaser/nfpm/pull/226/diff?src=pr&el=tree#diff-aW50ZXJuYWwvc2lnbi9yc2EuZ28=) | `53.84% <20.00%> (ø)` | |
| [internal/sign/pgp.go](https://codecov.io/gh/goreleaser/nfpm/pull/226/diff?src=pr&el=tree#diff-aW50ZXJuYWwvc2lnbi9wZ3AuZ28=) | `75.75% <50.00%> (ø)` | |
| [internal/glob/glob.go](https://codecov.io/gh/goreleaser/nfpm/pull/226/diff?src=pr&el=tree#diff-aW50ZXJuYWwvZ2xvYi9nbG9iLmdv) | `93.54% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/226?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/226?src=pr&el=footer). Last update [1666d2e...1eed7f5](https://codecov.io/gh/goreleaser/nfpm/pull/226?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/apk/apk.go b/apk/apk.go
index e2798fa..a68ee39 100644
--- a/apk/apk.go
+++ b/apk/apk.go
@@ -33,6 +33,7 @@ import (
 	"crypto/sha1" // nolint:gosec
 	"crypto/sha256"
 	"encoding/hex"
+	"errors"
 	"fmt"
 	"hash"
 	"io"
@@ -46,13 +47,9 @@ import (
 	"text/template"
 	"time"
 
+	"github.com/goreleaser/nfpm"
 	"github.com/goreleaser/nfpm/internal/files"
-
 	"github.com/goreleaser/nfpm/internal/sign"
-
-	"github.com/pkg/errors"
-
-	"github.com/goreleaser/nfpm"
 )
 
 // nolint: gochecknoinits
@@ -260,6 +257,8 @@ func createSignature(signatureTgz io.Writer, info *nfpm.Info, controlSHA1Digest
 	return nil
 }
 
+var errNoKeyAddress = errors.New("key name not set and maintainer mail address empty")
+
 func createSignatureBuilder(digest []byte, info *nfpm.Info) func(*tar.Writer) error {
 	return func(tw *tar.Writer) error {
 		signature, err := sign.RSASignSHA1Digest(digest,
@@ -273,9 +272,9 @@ func createSignatureBuilder(digest []byte, info *nfpm.Info) func(*tar.Writer) er
 		if keyname == "" {
 			addr, err := mail.ParseAddress(info.Maintainer)
 			if err != nil {
-				return errors.Wrap(err, "key name not set and unable to parse maintainer mail address")
+				return fmt.Errorf("key name not set and unable to parse maintainer mail address: %w", err)
 			} else if addr.Address == "" {
-				return errors.New("key name not set and maintainer mail address empty")
+				return errNoKeyAddress
 			}
 
 			keyname = addr.Address + ".rsa.pub"
@@ -370,10 +369,10 @@ func newScriptInsideTarGz(out *tar.Writer, path, dest string) error {
 
 func newItemInsideTarGz(out *tar.Writer, content []byte, header *tar.Header) error {
 	if err := out.WriteHeader(header); err != nil {
-		return errors.Wrapf(err, "cannot write header of %s file to control.tar.gz", header.Name)
+		return fmt.Errorf("cannot write header of %s file to control.tar.gz: %w", header.Name, err)
 	}
 	if _, err := out.Write(content); err != nil {
-		return errors.Wrapf(err, "cannot write %s file to control.tar.gz", header.Name)
+		return fmt.Errorf("cannot write %s file to control.tar.gz: %w", header.Name, err)
 	}
 	return nil
 }
@@ -444,7 +443,7 @@ func createSymlinksInsideTarGz(info *nfpm.Info, out *tar.Writer, created map[str
 func copyToTarAndDigest(src, dst string, tw *tar.Writer, sizep *int64, created map[string]bool) error {
 	file, err := os.OpenFile(src, os.O_RDONLY, 0600) //nolint:gosec
 	if err != nil {
-		return errors.Wrap(err, "could not add file to the archive")
+		return fmt.Errorf("could not add file to the archive: %w", err)
 	}
 	// don't care if it errs while closing...
 	defer file.Close() // nolint: errcheck
@@ -501,7 +500,7 @@ func createTree(tarw *tar.Writer, dst string, created map[string]bool) error {
 			Format:   tar.FormatGNU,
 			ModTime:  time.Now(),
 		}); err != nil {
-			return errors.Wrap(err, "failed to create folder")
+			return fmt.Errorf("failed to create folder: %w", err)
 		}
 		created[path] = true
 	}
diff --git a/deb/deb.go b/deb/deb.go
index 70b4c5c..9fc0b85 100644
--- a/deb/deb.go
+++ b/deb/deb.go
@@ -6,6 +6,7 @@ import (
 	"bytes"
 	"compress/gzip"
 	"crypto/md5" // nolint:gas
+	"errors"
 	"fmt"
 	"io"
 	"io/ioutil"
@@ -16,14 +17,11 @@ import (
 	"time"
 
 	"github.com/blakesmith/ar"
-	"github.com/pkg/errors"
-
-	"github.com/goreleaser/nfpm/internal/files"
-	"github.com/goreleaser/nfpm/internal/sign"
-
 	"github.com/goreleaser/chglog"
 
 	"github.com/goreleaser/nfpm"
+	"github.com/goreleaser/nfpm/internal/files"
+	"github.com/goreleaser/nfpm/internal/sign"
 )
 
 // nolint: gochecknoinits
@@ -75,8 +73,12 @@ func (*Deb) ConventionalFileName(info *nfpm.Info) string {
 	return fmt.Sprintf("%s_%s_%s.deb", info.Name, version, arch)
 }
 
+// ErrInvalidSignatureType happens if the signature type of a deb is not one of
+// origin, maint or archive.
+var ErrInvalidSignatureType = errors.New("invalid signature type")
+
 // Package writes a new deb package to the given writer using the given info.
-func (*Deb) Package(info *nfpm.Info, deb io.Writer) (err error) {
+func (*Deb) Package(info *nfpm.Info, deb io.Writer) (err error) { // nolint: funlen
 	arch, ok := archToDebian[info.Arch]
 	if ok {
 		info.Arch = arch
@@ -96,21 +98,22 @@ func (*Deb) Package(info *nfpm.Info, deb io.Writer) (err error) {
 
 	var w = ar.NewWriter(deb)
 	if err := w.WriteGlobalHeader(); err != nil {
-		return errors.Wrap(err, "cannot write ar header to deb file")
+		return fmt.Errorf("cannot write ar header to deb file: %w", err)
 	}
 
 	if err := addArFile(w, "debian-binary", debianBinary); err != nil {
-		return errors.Wrap(err, "cannot pack debian-binary")
+		return fmt.Errorf("cannot pack debian-binary: %w", err)
 	}
 
 	if err := addArFile(w, "control.tar.gz", controlTarGz); err != nil {
-		return errors.Wrap(err, "cannot add control.tar.gz to deb")
+		return fmt.Errorf("cannot add control.tar.gz to deb: %w", err)
 	}
 
 	if err := addArFile(w, "data.tar.gz", dataTarGz); err != nil {
-		return errors.Wrap(err, "cannot add data.tar.gz to deb")
+		return fmt.Errorf("cannot add data.tar.gz to deb: %w", err)
 	}
 
+	// TODO: refactor this
 	if info.Deb.Signature.KeyFile != "" {
 		data := io.MultiReader(bytes.NewReader(debianBinary), bytes.NewReader(controlTarGz),
 			bytes.NewReader(dataTarGz))
@@ -127,11 +130,15 @@ func (*Deb) Package(info *nfpm.Info, deb io.Writer) (err error) {
 		}
 
 		if sigType != "origin" && sigType != "maint" && sigType != "archive" {
-			return &nfpm.ErrSigningFailure{Err: errors.New("invalid signature type")}
+			return &nfpm.ErrSigningFailure{
+				Err: ErrInvalidSignatureType,
+			}
 		}
 
 		if err := addArFile(w, "_gpg"+sigType, sig); err != nil {
-			return &nfpm.ErrSigningFailure{Err: errors.Wrap(err, "add signature to ar file")}
+			return &nfpm.ErrSigningFailure{
+				Err: fmt.Errorf("add signature to ar file: %w", err),
+			}
 		}
 	}
 
@@ -146,7 +153,7 @@ func addArFile(w *ar.Writer, name string, body []byte) error {
 		ModTime: time.Now(),
 	}
 	if err := w.WriteHeader(&header); err != nil {
-		return errors.Wrap(err, "cannot write file header")
+		return fmt.Errorf("cannot write file header: %w", err)
 	}
 	_, err := w.Write(body)
 	return err
@@ -177,10 +184,10 @@ func createDataTarGz(info *nfpm.Info) (dataTarGz, md5sums []byte, instSize int64
 	}
 
 	if err := out.Close(); err != nil {
-		return nil, nil, 0, errors.Wrap(err, "closing data.tar.gz")
+		return nil, nil, 0, fmt.Errorf("closing data.tar.gz: %w", err)
 	}
 	if err := compress.Close(); err != nil {
-		return nil, nil, 0, errors.Wrap(err, "closing data.tar.gz")
+		return nil, nil, 0, fmt.Errorf("closing data.tar.gz: %w", err)
 	}
 
 	return buf.Bytes(), md5buf.Bytes(), instSize, nil
@@ -263,7 +270,7 @@ func createEmptyFoldersInsideTarGz(info *nfpm.Info, out *tar.Writer, created map
 func copyToTarAndDigest(tarw *tar.Writer, md5w io.Writer, src, dst string) (int64, error) {
 	file, err := os.OpenFile(src, os.O_RDONLY, 0600) //nolint:gosec
 	if err != nil {
-		return 0, errors.Wrap(err, "could not add file to the archive")
+		return 0, fmt.Errorf("could not add file to the archive: %w", err)
 	}
 	// don't care if it errs while closing...
 	defer file.Close() // nolint: errcheck,gosec
@@ -283,14 +290,14 @@ func copyToTarAndDigest(tarw *tar.Writer, md5w io.Writer, src, dst string) (int6
 		Format:  tar.FormatGNU,
 	}
 	if err := tarw.WriteHeader(&header); err != nil {
-		return 0, errors.Wrapf(err, "cannot write header of %s to data.tar.gz", src)
+		return 0, fmt.Errorf("cannot write header of %s to data.tar.gz: %w", src, err)
 	}
 	var digest = md5.New() // nolint:gas
 	if _, err := io.Copy(tarw, io.TeeReader(file, digest)); err != nil {
-		return 0, errors.Wrap(err, "failed to copy")
+		return 0, fmt.Errorf("failed to copy: %w", err)
 	}
 	if _, err := fmt.Fprintf(md5w, "%x  %s\n", digest.Sum(nil), header.Name); err != nil {
-		return 0, errors.Wrap(err, "failed to write md5")
+		return 0, fmt.Errorf("failed to write md5: %w", err)
 	}
 	return info.Size(), nil
 }
@@ -313,7 +320,7 @@ func createChangelogInsideTarGz(tarw *tar.Writer, md5w io.Writer, created map[st
 	}
 
 	if err = out.Close(); err != nil {
-		return 0, errors.Wrap(err, "closing changelog.gz")
+		return 0, fmt.Errorf("closing changelog.gz: %w", err)
 	}
 
 	changelogData := buf.Bytes()
@@ -418,20 +425,20 @@ func createControl(instSize int64, md5sums []byte, info *nfpm.Info) (controlTarG
 	}
 
 	if err := out.Close(); err != nil {
-		return nil, errors.Wrap(err, "closing control.tar.gz")
+		return nil, fmt.Errorf("closing control.tar.gz: %w", err)
 	}
 	if err := compress.Close(); err != nil {
-		return nil, errors.Wrap(err, "closing control.tar.gz")
+		return nil, fmt.Errorf("closing control.tar.gz: %w", err)
 	}
 	return buf.Bytes(), nil
 }
 
 func newItemInsideTarGz(out *tar.Writer, content []byte, header *tar.Header) error {
 	if err := out.WriteHeader(header); err != nil {
-		return errors.Wrapf(err, "cannot write header of %s file to control.tar.gz", header.Name)
+		return fmt.Errorf("cannot write header of %s file to control.tar.gz: %w", header.Name, err)
 	}
 	if _, err := out.Write(content); err != nil {
-		return errors.Wrapf(err, "cannot write %s file to control.tar.gz", header.Name)
+		return fmt.Errorf("cannot write %s file to control.tar.gz: %w", header.Name, err)
 	}
 	return nil
 }
@@ -490,7 +497,7 @@ func createTree(tarw *tar.Writer, dst string, created map[string]bool) error {
 			Format:   tar.FormatGNU,
 			ModTime:  time.Now(),
 		}); err != nil {
-			return errors.Wrap(err, "failed to create folder")
+			return fmt.Errorf("failed to create folder: %w", err)
 		}
 		created[path] = true
 	}
diff --git a/go.mod b/go.mod
index 1c7749b..2cde025 100644
--- a/go.mod
+++ b/go.mod
@@ -14,7 +14,6 @@ require (
 	github.com/imdario/mergo v0.3.11
 	github.com/mattn/go-zglob v0.0.3
 	github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 // indirect
-	github.com/pkg/errors v0.9.1
 	github.com/sassoftware/go-rpmutils v0.0.0-20190420191620-a8f1baeba37b
 	github.com/stretchr/objx v0.2.0 // indirect
 	github.com/stretchr/testify v1.6.1
diff --git a/internal/glob/glob.go b/internal/glob/glob.go
index 232cd7f..29834fe 100644
--- a/internal/glob/glob.go
+++ b/internal/glob/glob.go
@@ -8,7 +8,6 @@ import (
 	"strings"
 
 	"github.com/mattn/go-zglob"
-	"github.com/pkg/errors"
 )
 
 // longestCommonPrefix returns the longest prefix of all strings the argument
@@ -54,7 +53,7 @@ func (e ErrGlobNoMatch) Error() string {
 func Glob(glob, dst string) (map[string]string, error) {
 	matches, err := zglob.Glob(glob)
 	if err != nil {
-		return nil, errors.Wrap(err, glob)
+		return nil, fmt.Errorf("glob failed: %s: %w", glob, err)
 	}
 	if len(matches) == 0 {
 		return nil, ErrGlobNoMatch{glob}
diff --git a/internal/sign/pgp.go b/internal/sign/pgp.go
index 73b4a63..f3fafd1 100644
--- a/internal/sign/pgp.go
+++ b/internal/sign/pgp.go
@@ -2,11 +2,12 @@ package sign
 
 import (
 	"bytes"
+	"errors"
+	"fmt"
 	"io"
 	"io/ioutil"
 	"unicode"
 
-	"github.com/pkg/errors"
 	"golang.org/x/crypto/openpgp"
 
 	"github.com/goreleaser/nfpm"
@@ -36,14 +37,14 @@ func PGPSigner(keyFile, passphrase string) func([]byte) ([]byte, error) {
 func PGPArmoredDetachSign(message io.Reader, keyFile, passphrase string) ([]byte, error) {
 	key, err := readSigningKey(keyFile, passphrase)
 	if err != nil {
-		return nil, errors.Wrap(err, "armored detach sign")
+		return nil, fmt.Errorf("armored detach sign: %w", err)
 	}
 
 	var signature bytes.Buffer
 
 	err = openpgp.ArmoredDetachSign(&signature, key, message, nil)
 	if err != nil {
-		return nil, errors.Wrap(err, "armored detach sign")
+		return nil, fmt.Errorf("armored detach sign: %w", err)
 	}
 
 	return signature.Bytes(), nil
@@ -56,7 +57,7 @@ func PGPArmoredDetachSign(message io.Reader, keyFile, passphrase string) ([]byte
 func PGPVerify(message io.Reader, signature []byte, armoredPubKeyFile string) error {
 	keyFileContent, err := ioutil.ReadFile(armoredPubKeyFile)
 	if err != nil {
-		return errors.Wrap(err, "reading armored public key file")
+		return fmt.Errorf("reading armored public key file: %w", err)
 	}
 
 	var keyring openpgp.EntityList
@@ -64,12 +65,12 @@ func PGPVerify(message io.Reader, signature []byte, armoredPubKeyFile string) er
 	if isASCII(keyFileContent) {
 		keyring, err = openpgp.ReadArmoredKeyRing(bytes.NewReader(keyFileContent))
 		if err != nil {
-			return errors.Wrap(err, "decoding armored public key file")
+			return fmt.Errorf("decoding armored public key file: %w", err)
 		}
 	} else {
 		keyring, err = openpgp.ReadKeyRing(bytes.NewReader(keyFileContent))
 		if err != nil {
-			return errors.Wrap(err, "decoding public key file")
+			return fmt.Errorf("decoding public key file: %w", err)
 		}
 	}
 
@@ -82,10 +83,14 @@ func PGPVerify(message io.Reader, signature []byte, armoredPubKeyFile string) er
 	return err
 }
 
+var errMoreThanOneKey = errors.New("more than one signing key in keyring")
+var errNoKeys = errors.New("no signing key in keyring")
+var errNoPassword = errors.New("key is encrypted but no passphrase was provided")
+
 func readSigningKey(keyFile, passphrase string) (*openpgp.Entity, error) {
 	fileContent, err := ioutil.ReadFile(keyFile)
 	if err != nil {
-		return nil, errors.Wrap(err, "reading PGP key file")
+		return nil, fmt.Errorf("reading PGP key file: %w", err)
 	}
 
 	var entityList openpgp.EntityList
@@ -93,12 +98,12 @@ func readSigningKey(keyFile, passphrase string) (*openpgp.Entity, error) {
 	if isASCII(fileContent) {
 		entityList, err = openpgp.ReadArmoredKeyRing(bytes.NewReader(fileContent))
 		if err != nil {
-			return nil, errors.Wrap(err, "decoding armored PGP keyring")
+			return nil, fmt.Errorf("decoding armored PGP keyring: %w", err)
 		}
 	} else {
 		entityList, err = openpgp.ReadKeyRing(bytes.NewReader(fileContent))
 		if err != nil {
-			return nil, errors.Wrap(err, "decoding PGP keyring")
+			return nil, fmt.Errorf("decoding PGP keyring: %w", err)
 		}
 	}
 
@@ -114,24 +119,24 @@ func readSigningKey(keyFile, passphrase string) (*openpgp.Entity, error) {
 		}
 
 		if key != nil {
-			return nil, errors.New("more than one signing key in keyring")
+			return nil, errMoreThanOneKey
 		}
 
 		key = candidate
 	}
 
 	if key == nil {
-		return nil, errors.New("no signing key in keyring")
+		return nil, errNoKeys
 	}
 
 	if key.PrivateKey.Encrypted {
 		if passphrase == "" {
-			return nil, errors.New("key is encrypted but no passphrase was provided")
+			return nil, errNoPassword
 		}
 
 		err = key.PrivateKey.Decrypt([]byte(passphrase))
 		if err != nil {
-			return nil, errors.Wrap(err, "decrypt secret signing key")
+			return nil, fmt.Errorf("decrypt secret signing key: %w", err)
 		}
 	}
 
diff --git a/internal/sign/rsa.go b/internal/sign/rsa.go
index feaabe8..e50380b 100644
--- a/internal/sign/rsa.go
+++ b/internal/sign/rsa.go
@@ -7,40 +7,44 @@ import (
 	"crypto/sha1" // nolint:gosec
 	"crypto/x509"
 	"encoding/pem"
+	"errors"
+	"fmt"
 	"io"
 	"io/ioutil"
-
-	"github.com/pkg/errors"
 )
 
+var errNoPemBlock = errors.New("no PEM block found")
+var errDigestNotSH1 = errors.New("digest is not a SHA1 hash")
+var errNoPassphrase = errors.New("key is encrypted but no passphrase was provided")
+
 // RSASignSHA1Digest signs the provided SHA1 message digest. The key file
 // must be in the PEM format and can either be encrypted or not.
 func RSASignSHA1Digest(sha1Digest []byte, keyFile, passphrase string) ([]byte, error) {
 	if len(sha1Digest) != sha1.Size {
-		return nil, errors.New("digest is not a SHA1 hash")
+		return nil, errDigestNotSH1
 	}
 
 	keyFileContent, err := ioutil.ReadFile(keyFile)
 	if err != nil {
-		return nil, errors.Wrap(err, "reading key file")
+		return nil, fmt.Errorf("reading key file: %w", err)
 	}
 
 	block, _ := pem.Decode(keyFileContent)
 	if block == nil {
-		return nil, errors.New("parse PEM block with private key")
+		return nil, errNoPemBlock
 	}
 
 	blockData := block.Bytes
 	if x509.IsEncryptedPEMBlock(block) {
 		if passphrase == "" {
-			return nil, errors.New("key is encrypted but no passphrase was provided")
+			return nil, errNoPassphrase
 		}
 
 		var decryptedBlockData []byte
 
 		decryptedBlockData, err = x509.DecryptPEMBlock(block, []byte(passphrase))
 		if err != nil {
-			return nil, errors.Wrap(err, "decrypt private key PEM block")
+			return nil, fmt.Errorf("decrypt private key PEM block: %w", err)
 		}
 
 		blockData = decryptedBlockData
@@ -48,12 +52,12 @@ func RSASignSHA1Digest(sha1Digest []byte, keyFile, passphrase string) ([]byte, e
 
 	priv, err := x509.ParsePKCS1PrivateKey(blockData)
 	if err != nil {
-		return nil, errors.Wrap(err, "parse PKCS1 private key")
+		return nil, fmt.Errorf("parse PKCS1 private key: %w", err)
 	}
 
 	signature, err := priv.Sign(rand.Reader, sha1Digest, crypto.SHA1)
 	if err != nil {
-		return nil, errors.Wrap(err, "signing")
+		return nil, fmt.Errorf("signing: %w", err)
 	}
 
 	return signature, nil
@@ -63,7 +67,7 @@ func rsaSign(message io.Reader, keyFile, passphrase string) ([]byte, error) {
 	sha256Hash := sha1.New() // nolint:gosec
 	_, err := io.Copy(sha256Hash, message)
 	if err != nil {
-		return nil, errors.Wrap(err, "create SHA256 message digest")
+		return nil, fmt.Errorf("create SHA256 message digest: %w", err)
 	}
 
 	return RSASignSHA1Digest(sha256Hash.Sum(nil), keyFile, passphrase)
@@ -73,32 +77,32 @@ func rsaSign(message io.Reader, keyFile, passphrase string) ([]byte, error) {
 // provided SHA1 hash of a message. The key file must be in the PEM format.
 func RSAVerifySHA1Digest(sha1Digest, signature []byte, publicKeyFile string) error {
 	if len(sha1Digest) != sha1.Size {
-		return errors.New("digest is not a SHA1 hash")
+		return errDigestNotSH1
 	}
 
 	keyFileContent, err := ioutil.ReadFile(publicKeyFile)
 	if err != nil {
-		return errors.Wrap(err, "reading key file")
+		return fmt.Errorf("reading key file: %w", err)
 	}
 
 	block, _ := pem.Decode(keyFileContent)
 	if block == nil {
-		return errors.New("parse PEM block with public key")
+		return errNoPemBlock
 	}
 
 	pub, err := x509.ParsePKIXPublicKey(block.Bytes)
 	if err != nil {
-		return errors.Wrap(err, "parse PKIX public key")
+		return fmt.Errorf("parse PKIX public key: %w", err)
 	}
 
 	rsaPub, ok := pub.(*rsa.PublicKey)
 	if !ok {
-		return errors.Wrap(err, "public key is no RSA key")
+		return fmt.Errorf("public key is no RSA key: %w", err)
 	}
 
 	err = rsa.VerifyPKCS1v15(rsaPub, crypto.SHA1, sha1Digest, signature)
 	if err != nil {
-		return errors.Wrap(err, "verify PKCS1v15 signature")
+		return fmt.Errorf("verify PKCS1v15 signature: %w", err)
 	}
 
 	return nil
@@ -108,7 +112,7 @@ func rsaVerify(message io.Reader, signature []byte, publicKeyFile string) error
 	sha256Hash := sha1.New() // nolint:gosec
 	_, err := io.Copy(sha256Hash, message)
 	if err != nil {
-		return errors.Wrap(err, "create SHA1 message digest")
+		return fmt.Errorf("create SHA1 message digest: %w", err)
 	}
 
 	return RSAVerifySHA1Digest(sha256Hash.Sum(nil), signature, publicKeyFile)
diff --git a/nfpm.go b/nfpm.go
index a8a4d41..a03048e 100644
--- a/nfpm.go
+++ b/nfpm.go
@@ -13,7 +13,6 @@ import (
 	"github.com/Masterminds/semver/v3"
 	"github.com/goreleaser/chglog"
 	"github.com/imdario/mergo"
-	"github.com/pkg/errors"
 	"gopkg.in/yaml.v2"
 )
 
@@ -111,7 +110,7 @@ func (c *Config) Get(format string) (info *Info, err error) {
 	info = &Info{}
 	// make a deep copy of info
 	if err = mergo.Merge(info, c.Info); err != nil {
-		return nil, errors.Wrap(err, "failed to merge config into info")
+		return nil, fmt.Errorf("failed to merge config into info: %w", err)
 	}
 	override, ok := c.Overrides[format]
 	if !ok {
@@ -119,7 +118,7 @@ func (c *Config) Get(format string) (info *Info, err error) {
 		return info, nil
 	}
 	if err = mergo.Merge(&info.Overridables, override, mergo.WithOverride); err != nil {
-		return nil, errors.Wrap(err, "failed to merge overrides into info")
+		return nil, fmt.Errorf("failed to merge overrides into info: %w", err)
 	}
 	return info, nil
 }
diff --git a/rpm/rpm.go b/rpm/rpm.go
index ce2a8f5..7ff0400 100644
--- a/rpm/rpm.go
+++ b/rpm/rpm.go
@@ -13,7 +13,6 @@ import (
 	"time"
 
 	"github.com/google/rpmpack"
-	"github.com/pkg/errors"
 	"github.com/sassoftware/go-rpmutils/cpio"
 
 	"github.com/goreleaser/nfpm/internal/files"
@@ -370,7 +369,7 @@ func addSymlinksInsideRPM(info *nfpm.Info, rpm *rpmpack.RPM) {
 func copyToRPM(rpm *rpmpack.RPM, src, dst string, fileType rpmpack.FileType) error {
 	file, err := os.OpenFile(src, os.O_RDONLY, 0600) //nolint:gosec
 	if err != nil {
-		return errors.Wrap(err, "could not add file to the archive")
+		return fmt.Errorf("could not add file to the archive: %w", err)
 	}
 	// don't care if it errs while closing...
 	defer file.Close() // nolint: errcheck,gosec


Test patch:
diff --git a/apk/apk_test.go b/apk/apk_test.go
index fe5843e..8a6684e 100644
--- a/apk/apk_test.go
+++ b/apk/apk_test.go
@@ -177,7 +177,7 @@ func TestFileDoesNotExist(t *testing.T) {
 		}),
 		ioutil.Discard,
 	)
-	assert.EqualError(t, err, "../testdata/whatever.confzzz: file does not exist")
+	assert.EqualError(t, err, "glob failed: ../testdata/whatever.confzzz: file does not exist")
 }
 
 func TestNoFiles(t *testing.T) {
diff --git a/deb/deb_test.go b/deb/deb_test.go
index 75698e5..ed59f5e 100644
--- a/deb/deb_test.go
+++ b/deb/deb_test.go
@@ -278,7 +278,7 @@ func TestDebFileDoesNotExist(t *testing.T) {
 		}),
 		ioutil.Discard,
 	)
-	assert.EqualError(t, err, "../testdata/whatever.confzzz: file does not exist")
+	assert.EqualError(t, err, "glob failed: ../testdata/whatever.confzzz: file does not exist")
 }
 
 func TestDebNoFiles(t *testing.T) {
diff --git a/internal/glob/glob_test.go b/internal/glob/glob_test.go
index eb53d1f..b711cbb 100644
--- a/internal/glob/glob_test.go
+++ b/internal/glob/glob_test.go
@@ -50,7 +50,7 @@ func TestGlob(t *testing.T) {
 	assert.Equal(t, "/foo/bar/test_b.txt", singleFile["testdata/dir_a/dir_b/test_b.txt"])
 
 	nilvalue, err := Glob("does/not/exist", "/foo/bar")
-	assert.EqualError(t, err, "does/not/exist: file does not exist")
+	assert.EqualError(t, err, "glob failed: does/not/exist: file does not exist")
 	assert.Nil(t, nilvalue)
 
 	nomatches, err := Glob("testdata/nothing*", "/foo/bar")
diff --git a/rpm/rpm_test.go b/rpm/rpm_test.go
index 8e91d50..911368f 100644
--- a/rpm/rpm_test.go
+++ b/rpm/rpm_test.go
@@ -340,7 +340,7 @@ func TestRPMFileDoesNotExist(t *testing.T) {
 		"../testdata/whatever.confzzz": "/etc/fake/fake.conf",
 	}
 	var err = Default.Package(info, ioutil.Discard)
-	assert.EqualError(t, err, "../testdata/whatever.confzzz: file does not exist")
+	assert.EqualError(t, err, "glob failed: ../testdata/whatever.confzzz: file does not exist")
 }
 
 func TestRPMMultiArch(t *testing.T) {