diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 68e82df..8f45eb8 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -27,7 +27,7 @@ jobs: UnitTest: strategy: matrix: - go-version: [1.16.x] + go-version: [1.17.x] os: [ubuntu-latest] runs-on: ${{ matrix.os }} env: diff --git a/audit/log/file.go b/audit/log/file.go index a7c1e72..555cb13 100644 --- a/audit/log/file.go +++ b/audit/log/file.go @@ -7,14 +7,14 @@ import ( "path/filepath" "github.com/go-phorce/dolly/audit" - "github.com/juju/errors" + "github.com/pkg/errors" lumberjack "gopkg.in/natefinch/lumberjack.v2" ) // New return a new instance of an Auditor that writes audit entries to a local log file func New(fileprefix, directory string, maxAgeDays int, maxSizeMb int) (audit.Auditor, error) { if err := os.MkdirAll(directory, 0755); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } res := fileAuditor{ fileWriter: lumberjack.Logger{ diff --git a/cmd/dollypki/cli/cli.go b/cmd/dollypki/cli/cli.go index db1bb63..e1ad23c 100644 --- a/cmd/dollypki/cli/cli.go +++ b/cmd/dollypki/cli/cli.go @@ -11,7 +11,7 @@ import ( "github.com/go-phorce/dolly/ctl" "github.com/go-phorce/dolly/xlog" "github.com/go-phorce/dolly/xpki/cryptoprov" - "github.com/juju/errors" + "github.com/pkg/errors" ) // ReturnCode is the type that your command returns, these map to standard process return codes @@ -87,7 +87,7 @@ func (cli *Cli) EnsureCryptoProvider() error { var err error cli.crypto, err = cryptoprov.Load(*cli.flags.hsmConfig, nil) if err != nil { - return errors.Annotate(err, "unable to initialize crypto providers") + return errors.WithMessage(err, "unable to initialize crypto providers") } return nil diff --git a/cmd/dollypki/csr/gencert.go b/cmd/dollypki/csr/gencert.go index 7f980b7..a3b1542 100644 --- a/cmd/dollypki/csr/gencert.go +++ b/cmd/dollypki/csr/gencert.go @@ -12,7 +12,7 @@ import ( "github.com/go-phorce/dolly/cmd/dollypki/cli" "github.com/go-phorce/dolly/ctl" "github.com/go-phorce/dolly/xpki/csrprov" - "github.com/juju/errors" + "github.com/pkg/errors" ) // GenCertFlags specifies flags for GenCert command @@ -85,7 +85,7 @@ func GenCert(c ctl.Control, p interface{}) error { // Load CSR csrf, err := cli.ReadStdin(*flags.CsrProfile) if err != nil { - return errors.Annotate(err, "read CSR profile") + return errors.WithMessage(err, "read CSR profile") } req := csrprov.CertificateRequest{ @@ -95,7 +95,7 @@ func GenCert(c ctl.Control, p interface{}) error { err = json.Unmarshal(csrf, &req) if err != nil { - return errors.Annotate(err, "invalid CSR") + return errors.WithMessage(err, "invalid CSR") } if req.CA != nil { @@ -105,7 +105,7 @@ func GenCert(c ctl.Control, p interface{}) error { // Load ca-config cacfg, err := cfsslconfig.LoadFile(*flags.CAConfig) if err != nil { - return errors.Annotate(err, "ca-config") + return errors.WithMessage(err, "ca-config") } if cacfg.Signing == nil { return errors.New("missing signing policy in ca-config") @@ -117,13 +117,13 @@ func GenCert(c ctl.Control, p interface{}) error { // ensure that signer can be created before the key is generated s, _, err := csrprov.NewLocalCASignerFromFile(cryptoprov, *flags.CA, *flags.CAKey, cacfg.Signing) if err != nil { - return errors.Annotate(err, "create signer") + return errors.WithMessage(err, "create signer") } var key, csrPEM []byte csrPEM, key, _, _, err = prov.ProcessCsrRequest(&req) if err != nil { - return errors.Annotate(err, "ProcessRequest") + return errors.WithMessage(err, "ProcessRequest") } signReq := signer.SignRequest{ @@ -140,15 +140,15 @@ func GenCert(c ctl.Control, p interface{}) error { err = cli.WriteFile(baseName+".pem", cert, 0664) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } err = cli.WriteFile(baseName+".csr", csrPEM, 0664) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } err = cli.WriteFile(baseName+"-key.pem", key, 0600) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } } diff --git a/cmd/dollypki/csr/genkey.go b/cmd/dollypki/csr/genkey.go index f360791..b34b0b4 100644 --- a/cmd/dollypki/csr/genkey.go +++ b/cmd/dollypki/csr/genkey.go @@ -7,7 +7,7 @@ import ( "github.com/go-phorce/dolly/cmd/dollypki/cli" "github.com/go-phorce/dolly/ctl" "github.com/go-phorce/dolly/xpki/csrprov" - "github.com/juju/errors" + "github.com/pkg/errors" ) // GenKeyFlags specifies flags for GenKey command @@ -56,7 +56,7 @@ func GenKey(c ctl.Control, p interface{}) error { csrf, err := cli.ReadStdin(*flags.CsrProfile) if err != nil { - return errors.Annotate(err, "read CSR profile") + return errors.WithMessage(err, "read CSR profile") } req := csrprov.CertificateRequest{ @@ -66,14 +66,14 @@ func GenKey(c ctl.Control, p interface{}) error { err = json.Unmarshal(csrf, &req) if err != nil { - return errors.Annotate(err, "invalid CSR") + return errors.WithMessage(err, "invalid CSR") } if *flags.Initca { var key, csrPEM, cert []byte cert, csrPEM, key, err = prov.NewRoot(&req) if err != nil { - return errors.Annotate(err, "init CA") + return errors.WithMessage(err, "init CA") } if *flags.Output == "" { @@ -83,15 +83,15 @@ func GenKey(c ctl.Control, p interface{}) error { err = cli.WriteFile(baseName+".pem", cert, 0664) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } err = cli.WriteFile(baseName+".csr", csrPEM, 0664) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } err = cli.WriteFile(baseName+"-key.pem", key, 0600) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } } } else { @@ -103,7 +103,7 @@ func GenKey(c ctl.Control, p interface{}) error { csrPEM, key, _, _, err = prov.ProcessCsrRequest(&req) if err != nil { key = nil - return errors.Annotate(err, "ProcessCsrRequest") + return errors.WithMessage(err, "ProcessCsrRequest") } if *flags.Output == "" { @@ -113,11 +113,11 @@ func GenKey(c ctl.Control, p interface{}) error { err = cli.WriteFile(baseName+".csr", csrPEM, 0664) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } err = cli.WriteFile(baseName+"-key.pem", key, 0600) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } } } diff --git a/cmd/dollypki/csr/signcert.go b/cmd/dollypki/csr/signcert.go index 925b168..3519cb6 100644 --- a/cmd/dollypki/csr/signcert.go +++ b/cmd/dollypki/csr/signcert.go @@ -6,7 +6,7 @@ import ( "github.com/go-phorce/dolly/cmd/dollypki/cli" "github.com/go-phorce/dolly/ctl" "github.com/go-phorce/dolly/xpki/csrprov" - "github.com/juju/errors" + "github.com/pkg/errors" ) // SignCertFlags specifies flags for SignCert command @@ -67,13 +67,13 @@ func SignCert(c ctl.Control, p interface{}) error { // Load CSR csrPEM, err := cli.ReadStdin(*flags.Csr) if err != nil { - return errors.Annotate(err, "read CSR") + return errors.WithMessage(err, "read CSR") } // Load ca-config cacfg, err := cfsslconfig.LoadFile(*flags.CAConfig) if err != nil { - return errors.Annotate(err, "ca-config") + return errors.WithMessage(err, "ca-config") } if cacfg.Signing == nil { return errors.New("missing signing policy in ca-config") @@ -89,7 +89,7 @@ func SignCert(c ctl.Control, p interface{}) error { s, _, err := csrprov.NewLocalCASignerFromFile(cryptoprov, *flags.CA, *flags.CAKey, cacfg.Signing) if err != nil { - return errors.Annotate(err, "create signer") + return errors.WithMessage(err, "create signer") } signReq := signer.SignRequest{ @@ -106,11 +106,11 @@ func SignCert(c ctl.Control, p interface{}) error { err = cli.WriteFile(baseName+".pem", cert, 0664) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } err = cli.WriteFile(baseName+".csr", csrPEM, 0664) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } } diff --git a/cmd/dollypki/hsm/genkey.go b/cmd/dollypki/hsm/genkey.go index 201248c..6c281d2 100644 --- a/cmd/dollypki/hsm/genkey.go +++ b/cmd/dollypki/hsm/genkey.go @@ -12,7 +12,7 @@ import ( "github.com/go-phorce/dolly/cmd/dollypki/cli" "github.com/go-phorce/dolly/ctl" "github.com/go-phorce/dolly/xpki/csrprov" - "github.com/juju/errors" + "github.com/pkg/errors" ) // GenKeyFlags specifies flags for GenKey command @@ -86,17 +86,17 @@ func GenKey(c ctl.Control, p interface{}) error { req := csr.NewKeyRequest(prefixKeyLabel(*flags.Label), *flags.Algo, *flags.Size, purpose) prv, err := req.Generate() if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } keyID, _, err := crypto.IdentifyKey(prv) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } uri, key, err := crypto.ExportKey(keyID) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } if key == nil { @@ -108,7 +108,7 @@ func GenKey(c ctl.Control, p interface{}) error { } else { err = cli.WriteFile(*flags.Output, key, 0600) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } } diff --git a/cmd/dollypki/hsm/keyinfo.go b/cmd/dollypki/hsm/keyinfo.go index 1896495..1489e93 100644 --- a/cmd/dollypki/hsm/keyinfo.go +++ b/cmd/dollypki/hsm/keyinfo.go @@ -7,7 +7,7 @@ import ( "github.com/go-phorce/dolly/cmd/dollypki/cli" "github.com/go-phorce/dolly/ctl" "github.com/go-phorce/dolly/xpki/cryptoprov" - "github.com/juju/errors" + "github.com/pkg/errors" ) // KeyInfoFlags specifies flags for the key info action diff --git a/cmd/dollypki/hsm/lskey.go b/cmd/dollypki/hsm/lskey.go index b53b0a7..ed80afe 100644 --- a/cmd/dollypki/hsm/lskey.go +++ b/cmd/dollypki/hsm/lskey.go @@ -7,7 +7,7 @@ import ( "github.com/go-phorce/dolly/cmd/dollypki/cli" "github.com/go-phorce/dolly/ctl" "github.com/go-phorce/dolly/xpki/cryptoprov" - "github.com/juju/errors" + "github.com/pkg/errors" ) // LsKeyFlags specifies flags for the Keys action @@ -78,7 +78,7 @@ func Keys(c ctl.Control, p interface{}) error { return nil }) if err != nil { - return errors.Annotatef(err, "failed to list keys on slot %d", slotID) + return errors.WithMessagef(err, "failed to list keys on slot %d", slotID) } if *flags.Prefix != "" && count == 0 { diff --git a/cmd/dollypki/hsm/mockhsm_test.go b/cmd/dollypki/hsm/mockhsm_test.go index c8a96db..ee7f24f 100644 --- a/cmd/dollypki/hsm/mockhsm_test.go +++ b/cmd/dollypki/hsm/mockhsm_test.go @@ -13,7 +13,7 @@ import ( "github.com/go-phorce/dolly/cmd/dollypki/hsm" "github.com/go-phorce/dolly/cmd/dollypki/testsuite" "github.com/go-phorce/dolly/xpki/cryptoprov" - "github.com/juju/errors" + "github.com/pkg/errors" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" diff --git a/cmd/dollypki/hsm/rmkey.go b/cmd/dollypki/hsm/rmkey.go index 53c2e11..80b0c8a 100644 --- a/cmd/dollypki/hsm/rmkey.go +++ b/cmd/dollypki/hsm/rmkey.go @@ -7,7 +7,7 @@ import ( "github.com/go-phorce/dolly/cmd/dollypki/cli" "github.com/go-phorce/dolly/ctl" "github.com/go-phorce/dolly/xpki/cryptoprov" - "github.com/juju/errors" + "github.com/pkg/errors" ) // RmKeyFlags specifies flags for the delete key action @@ -90,7 +90,7 @@ func RmKey(c ctl.Control, p interface{}) error { return nil }) if err != nil { - return errors.Annotatef(err, "failed to list keys on slot %d", slotID) + return errors.WithMessagef(err, "failed to list keys on slot %d", slotID) } if len(keysToDestroy) == 0 { @@ -111,7 +111,7 @@ func RmKey(c ctl.Control, p interface{}) error { } else { isConfirmed, err := ctl.AskForConfirmation(out, c.Reader(), "WARNING: Destroyed keys can not be recovered. Type Y to continue or N to cancel.") if err != nil { - return errors.Annotatef(err, "unable to get a confirmation to destroy keys") + return errors.WithMessagef(err, "unable to get a confirmation to destroy keys") } if !isConfirmed { @@ -143,7 +143,7 @@ func destroyKeys(c ctl.Control, keyProv cryptoprov.KeyManager, slotID uint, keys func destroyKey(c ctl.Control, keyProv cryptoprov.KeyManager, slotID uint, keyID string) error { err := keyProv.DestroyKeyPairOnSlot(slotID, keyID) if err != nil { - return errors.Annotatef(err, "unable to destroy key %q on slot %d", keyID, slotID) + return errors.WithMessagef(err, "unable to destroy key %q on slot %d", keyID, slotID) } fmt.Fprintf(c.Writer(), "destroyed key: %s\n", keyID) return nil diff --git a/cmd/dollypki/hsm/slots.go b/cmd/dollypki/hsm/slots.go index 2960907..b96d53a 100644 --- a/cmd/dollypki/hsm/slots.go +++ b/cmd/dollypki/hsm/slots.go @@ -6,7 +6,7 @@ import ( "github.com/go-phorce/dolly/cmd/dollypki/cli" "github.com/go-phorce/dolly/ctl" "github.com/go-phorce/dolly/xpki/cryptoprov" - "github.com/juju/errors" + "github.com/pkg/errors" ) // Slots shows hsm slots @@ -24,7 +24,7 @@ func Slots(c ctl.Control, _ interface{}) error { return nil }) if err != nil { - return errors.Annotate(err, "unable to list slots") + return errors.WithMessage(err, "unable to list slots") } return nil diff --git a/ctl/ctl.go b/ctl/ctl.go index cef5d7c..d229f97 100644 --- a/ctl/ctl.go +++ b/ctl/ctl.go @@ -11,7 +11,7 @@ import ( "github.com/go-phorce/dolly/xhttp/marshal" "github.com/go-phorce/dolly/xlog" - "github.com/juju/errors" + "github.com/pkg/errors" ) var logger = xlog.NewPackageLogger("github.com/go-phorce/dolly", "ctl") @@ -132,7 +132,7 @@ func (ctl *Ctl) ReturnCode() ReturnCode { // Fail the execution and return error func (ctl *Ctl) Fail(msg string, err error) error { ctl.rc = RCFailed - logger.Errorf("message=%q, err=[%s]", msg, errors.ErrorStack(err)) + logger.Errorf("message=%q, err=[%+v]", msg, err) return err } @@ -175,7 +175,7 @@ var newLine = []byte("\n") func WriteJSON(out io.Writer, value interface{}) error { json, err := marshal.EncodeBytes(marshal.PrettyPrint, value) if err != nil { - return errors.Annotate(err, "failed to encode") + return errors.WithMessage(err, "failed to encode") } out.Write(json) diff --git a/fileutil/folders.go b/fileutil/folders.go index a56434d..aae7cbf 100644 --- a/fileutil/folders.go +++ b/fileutil/folders.go @@ -3,7 +3,7 @@ package fileutil import ( "os" - "github.com/juju/errors" + "github.com/pkg/errors" ) // FolderExists ensures that folder exists @@ -14,7 +14,7 @@ func FolderExists(dir string) error { stat, err := os.Stat(dir) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } if !stat.IsDir() { @@ -32,7 +32,7 @@ func FileExists(file string) error { stat, err := os.Stat(file) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } if stat.IsDir() { diff --git a/fileutil/load.go b/fileutil/load.go index 13fae55..a5d931b 100644 --- a/fileutil/load.go +++ b/fileutil/load.go @@ -5,7 +5,7 @@ import ( "os" "strings" - "github.com/juju/errors" + "github.com/pkg/errors" ) const ( @@ -22,7 +22,7 @@ func LoadConfigWithSchema(config string) (string, error) { fn := strings.TrimPrefix(config, FileSource) f, err := ioutil.ReadFile(fn) if err != nil { - return config, errors.Trace(err) + return config, errors.WithStack(err) } // file content config = string(f) @@ -44,14 +44,14 @@ func SaveConfigWithSchema(path, value string) error { fn := strings.TrimPrefix(path, FileSource) err := ioutil.WriteFile(fn, []byte(value), 0644) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } } else if strings.HasPrefix(path, EnvSource) { env := strings.TrimPrefix(path, EnvSource) // ENV content err := os.Setenv(env, value) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } } diff --git a/fileutil/reloader/reloader.go b/fileutil/reloader/reloader.go index ad49a56..3bfbb79 100644 --- a/fileutil/reloader/reloader.go +++ b/fileutil/reloader/reloader.go @@ -7,7 +7,7 @@ import ( "time" "github.com/go-phorce/dolly/xlog" - "github.com/juju/errors" + "github.com/pkg/errors" ) var logger = xlog.NewPackageLogger("github.com/go-phorce/dolly/fileutil", "reloader") @@ -64,7 +64,7 @@ func NewReloader(filePath string, checkInterval time.Duration, onChangedFunc OnC result.fileModifiedAt = fi.ModTime() err := result.Reload() if err != nil { - logger.Errorf("err=[%v]", errors.ErrorStack(err)) + logger.Errorf("err=[%+v]", err) } } } else { diff --git a/fileutil/resolve/resolve.go b/fileutil/resolve/resolve.go index c065864..db7c680 100644 --- a/fileutil/resolve/resolve.go +++ b/fileutil/resolve/resolve.go @@ -4,7 +4,7 @@ import ( "os" "path/filepath" - "github.com/juju/errors" + "github.com/pkg/errors" ) // Directory returns absolute dir name relative to baseDir, @@ -21,10 +21,10 @@ func Directory(dir string, baseDir string, create bool) (resolved string, err er if _, err := os.Stat(resolved); os.IsNotExist(err) { if create { if err = os.MkdirAll(resolved, 0744); err != nil { - return "", errors.Annotatef(err, "crerate dir: %q", resolved) + return "", errors.WithMessagef(err, "crerate dir: %q", resolved) } } else { - return resolved, errors.NewNotFound(err, resolved) + return resolved, errors.WithMessagef(err, "not found: %v", resolved) } } return resolved, nil @@ -42,7 +42,7 @@ func File(file string, baseDir string) (resolved string, err error) { resolved = filepath.Join(baseDir, file) } if _, err := os.Stat(resolved); os.IsNotExist(err) { - return resolved, errors.NewNotFound(err, resolved) + return resolved, errors.WithMessagef(err, "not found: %v", resolved) } return resolved, nil } diff --git a/go.mod b/go.mod index e40377f..6b5cea6 100644 --- a/go.mod +++ b/go.mod @@ -26,8 +26,6 @@ require ( github.com/jmhodges/clock v0.0.0-20160418191101-880ee4c33548 // indirect github.com/jmoiron/sqlx v1.2.0 // indirect github.com/jteeuwen/go-bindata v3.0.7+incompatible - github.com/juju/errors v0.0.0-20200330140219-3fe23663418f - github.com/juju/testing v0.0.0-20210324180055-18c50b0c2098 // indirect github.com/julienschmidt/httprouter v1.3.0 github.com/kisielk/sqlstruct v0.0.0-20150923205031-648daed35d49 // indirect github.com/lib/pq v1.7.0 // indirect @@ -35,6 +33,7 @@ require ( github.com/mattn/goveralls v0.0.9 github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect github.com/miekg/pkcs11 v1.0.3 + github.com/pkg/errors v0.9.1 github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.11.0 github.com/prometheus/client_model v0.2.0 // indirect @@ -66,6 +65,8 @@ require ( gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) +require github.com/kr/text v0.2.0 // indirect + replace golang.org/x/text => golang.org/x/text v0.3.6 replace github.com/yuin/goldmark => github.com/yuin/goldmark v1.4.0 diff --git a/go.sum b/go.sum index 150c1c6..8ce6cd1 100644 --- a/go.sum +++ b/go.sum @@ -193,34 +193,6 @@ github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/ github.com/jteeuwen/go-bindata v3.0.7+incompatible h1:91Uy4d9SYVr1kyTJ15wJsog+esAZZl7JmEfTkwmhJts= github.com/jteeuwen/go-bindata v3.0.7+incompatible/go.mod h1:JVvhzYOiGBnFSYRyV00iY8q7/0PThjIYav1p9h5dmKs= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/juju/ansiterm v0.0.0-20160907234532-b99631de12cf/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU= -github.com/juju/clock v0.0.0-20190205081909-9c5c9712527c/go.mod h1:nD0vlnrUjcjJhqN5WuCWZyzfd5AHZAC9/ajvbSx69xA= -github.com/juju/cmd v0.0.0-20171107070456-e74f39857ca0/go.mod h1:yWJQHl73rdSX4DHVKGqkAip+huBslxRwS8m9CrOLq18= -github.com/juju/collections v0.0.0-20200605021417-0d0ec82b7271/go.mod h1:5XgO71dV1JClcOJE+4dzdn4HrI5LiyKd7PlVG6eZYhY= -github.com/juju/errors v0.0.0-20150916125642-1b5e39b83d18/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q= -github.com/juju/errors v0.0.0-20200330140219-3fe23663418f h1:MCOvExGLpaSIzLYB4iQXEHP4jYVU6vmzLNQPdMVrxnM= -github.com/juju/errors v0.0.0-20200330140219-3fe23663418f/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q= -github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE= -github.com/juju/httpprof v0.0.0-20141217160036-14bf14c30767/go.mod h1:+MaLYz4PumRkkyHYeXJ2G5g5cIW0sli2bOfpmbaMV/g= -github.com/juju/loggo v0.0.0-20170605014607-8232ab8918d9/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U= -github.com/juju/loggo v0.0.0-20200526014432-9ce3a2e09b5e h1:FdDd7bdI6cjq5vaoYlK1mfQYfF9sF2VZw8VEZMsl5t8= -github.com/juju/loggo v0.0.0-20200526014432-9ce3a2e09b5e/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U= -github.com/juju/mgo/v2 v2.0.0-20210302023703-70d5d206e208 h1:/WiCm+Vpj87e4QWuWwPD/bNE9kDrWCLvPBHOQNcG2+A= -github.com/juju/mgo/v2 v2.0.0-20210302023703-70d5d206e208/go.mod h1:0OChplkvPTZ174D2FYZXg4IB9hbEwyHkD+zT+/eK+Fg= -github.com/juju/mutex v0.0.0-20171110020013-1fe2a4bf0a3a/go.mod h1:Y3oOzHH8CQ0Ppt0oCKJ2JFO81/EsWenH5AEqigLH+yY= -github.com/juju/retry v0.0.0-20151029024821-62c620325291/go.mod h1:OohPQGsr4pnxwD5YljhQ+TZnuVRYpa5irjugL1Yuif4= -github.com/juju/retry v0.0.0-20180821225755-9058e192b216/go.mod h1:OohPQGsr4pnxwD5YljhQ+TZnuVRYpa5irjugL1Yuif4= -github.com/juju/testing v0.0.0-20180402130637-44801989f0f7/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA= -github.com/juju/testing v0.0.0-20190723135506-ce30eb24acd2/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA= -github.com/juju/testing v0.0.0-20210324180055-18c50b0c2098 h1:yrhek184cGp0IRyHg0uV1khLaorNg6GtDLkry4oNNjE= -github.com/juju/testing v0.0.0-20210324180055-18c50b0c2098/go.mod h1:7lxZW0B50+xdGFkvhAb8bwAGt6IU87JB1H9w4t8MNVM= -github.com/juju/utils v0.0.0-20180424094159-2000ea4ff043/go.mod h1:6/KLg8Wz/y2KVGWEpkK9vMNGkOnu4k/cqs8Z1fKjTOk= -github.com/juju/utils v0.0.0-20200116185830-d40c2fe10647/go.mod h1:6/KLg8Wz/y2KVGWEpkK9vMNGkOnu4k/cqs8Z1fKjTOk= -github.com/juju/utils/v2 v2.0.0-20200923005554-4646bfea2ef1/go.mod h1:fdlDtQlzundleLLz/ggoYinEt/LmnrpNKcNTABQATNI= -github.com/juju/version v0.0.0-20161031051906-1f41e27e54f2/go.mod h1:kE8gK5X0CImdr7qpSKl3xB2PmpySSmfj7zVbkZFs81U= -github.com/juju/version v0.0.0-20180108022336-b64dbd566305/go.mod h1:kE8gK5X0CImdr7qpSKl3xB2PmpySSmfj7zVbkZFs81U= -github.com/juju/version v0.0.0-20191219164919-81c1be00b9a6/go.mod h1:kE8gK5X0CImdr7qpSKl3xB2PmpySSmfj7zVbkZFs81U= -github.com/julienschmidt/httprouter v1.1.1-0.20151013225520-77a895ad01eb/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= @@ -247,15 +219,8 @@ github.com/lib/pq v1.7.0 h1:h93mCPfUSkaul3Ka/VG8uZdmW1uMHDGxzu0NWHuJmHY= github.com/lib/pq v1.7.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= -github.com/lunixbochs/vtclean v0.0.0-20160125035106-4fbf7632a2c6/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= -github.com/masterzen/azure-sdk-for-go v3.2.0-beta.0.20161014135628-ee4f0065d00c+incompatible/go.mod h1:mf8fjOu33zCqxUjuiU3I8S1lJMyEAlH+0F2+M5xl3hE= -github.com/masterzen/simplexml v0.0.0-20160608183007-4572e39b1ab9/go.mod h1:kCEbxUJlNDEBNbdQMkPSp6yaKcRXVI6f4ddk8Riv4bc= -github.com/masterzen/winrm v0.0.0-20161014151040-7a535cd943fc/go.mod h1:CfZSN7zwz5gJiFhZJz49Uzk7mEBHIceWmbFmYx7Hf7E= -github.com/masterzen/xmlpath v0.0.0-20140218185901-13f4951698ad/go.mod h1:A0zPC53iKKKcXYxr4ROjpQRQ5FgJXtelNdSmHHuq/tY= -github.com/mattn/go-colorable v0.0.6/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-isatty v0.0.0-20160806122752-66b8e73f3f5c/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= @@ -294,7 +259,6 @@ github.com/nats-io/nats.go v1.11.0/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/ github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E= -github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U= github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= @@ -318,6 +282,7 @@ github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0 github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -420,14 +385,12 @@ go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+ go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= -golang.org/x/crypto v0.0.0-20180214000028-650f4a345ab4/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201124201722-c8d3bf9c5392/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI= @@ -449,7 +412,6 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180406214816-61147c48b25b/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -470,7 +432,6 @@ golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= @@ -598,26 +559,19 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20160105164936-4f90aeace3a2/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= -gopkg.in/errgo.v1 v1.0.0-20161222125816-442357a80af5/go.mod h1:u0ALmqvLRxLI95fkdCEWrE6mhWYZW1aMOJHp5YXLHTg= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= -gopkg.in/httprequest.v1 v1.1.1/go.mod h1:/CkavNL+g3qLOrpFHVrEx4NKepeqR4XTZWNj4sGGjz0= -gopkg.in/mgo.v2 v2.0.0-20160818015218-f2b6f6c918c4/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= -gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637/go.mod h1:BHsqpu/nsuzkT5BpiH1EMZPLyqSMM8JbIavyFACoFNk= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= -gopkg.in/yaml.v2 v2.0.0-20170712054546-1be3d31502d6/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= @@ -634,7 +588,5 @@ honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM= -launchpad.net/xmlpath v0.0.0-20130614043138-000000000004/go.mod h1:vqyExLOM3qBx7mvYRkoxjSCF945s0mbe7YynlKYXtsA= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= diff --git a/metrics/inmem.go b/metrics/inmem.go index 556e525..b5ed988 100644 --- a/metrics/inmem.go +++ b/metrics/inmem.go @@ -9,7 +9,7 @@ import ( "sync" "time" - "github.com/juju/errors" + "github.com/pkg/errors" ) // InmemSink provides a MetricSink that does in-memory aggregation @@ -131,12 +131,12 @@ func NewInmemSinkFromURL(u *url.URL) (Sink, error) { interval, err := time.ParseDuration(params.Get("interval")) if err != nil { - return nil, errors.Annotate(err, "bad 'interval' param") + return nil, errors.WithMessage(err, "bad 'interval' param") } retain, err := time.ParseDuration(params.Get("retain")) if err != nil { - return nil, errors.Annotate(err, "bad 'retain' param") + return nil, errors.WithMessage(err, "bad 'retain' param") } return NewInmemSink(interval, retain), nil diff --git a/metrics/sink.go b/metrics/sink.go index 1c0223e..411dd11 100644 --- a/metrics/sink.go +++ b/metrics/sink.go @@ -4,7 +4,7 @@ import ( "net/url" "time" - "github.com/juju/errors" + "github.com/pkg/errors" ) // Tag is used to add dimentions to metrics diff --git a/metrics/statsd.go b/metrics/statsd.go index 8ffbf81..2d6410e 100644 --- a/metrics/statsd.go +++ b/metrics/statsd.go @@ -7,8 +7,6 @@ import ( "net/url" "strings" "time" - - "github.com/juju/errors" ) const ( @@ -115,7 +113,7 @@ CONNECT: // Attempt to connect sock, err = net.Dial("udp", s.addr) if err != nil { - logger.Errorf("reason=connecting, err=[%v]", errors.ErrorStack(err)) + logger.Errorf("reason=connecting, err=[%+v]", err) goto WAIT } @@ -132,7 +130,7 @@ CONNECT: _, err := sock.Write(buf.Bytes()) buf.Reset() if err != nil { - logger.Errorf("reason=writing, err=[%v]", errors.ErrorStack(err)) + logger.Errorf("reason=writing, err=[%+v]", err) goto WAIT } } @@ -148,7 +146,7 @@ CONNECT: _, err := sock.Write(buf.Bytes()) buf.Reset() if err != nil { - logger.Errorf("reason=flushing, err=[%v]", errors.ErrorStack(err)) + logger.Errorf("reason=flushing, err=[%+v]", err) goto WAIT } } diff --git a/netutil/localip.go b/netutil/localip.go index acdf10e..67ea3ff 100644 --- a/netutil/localip.go +++ b/netutil/localip.go @@ -4,7 +4,7 @@ import ( "net" "time" - "github.com/juju/errors" + "github.com/pkg/errors" ) var cidrs []*net.IPNet @@ -53,7 +53,7 @@ func IsPrivateAddress(address string) (bool, error) { func GetLocalIP() (string, error) { addrs, err := net.InterfaceAddrs() if err != nil { - return "", errors.Trace(err) + return "", errors.WithStack(err) } for _, address := range addrs { // check the address type and if it is not a loopback the display it diff --git a/netutil/nodeinfo.go b/netutil/nodeinfo.go index 72c3812..e2a6780 100644 --- a/netutil/nodeinfo.go +++ b/netutil/nodeinfo.go @@ -3,7 +3,7 @@ package netutil import ( "os" - "github.com/juju/errors" + "github.com/pkg/errors" ) // NodeInfo is an interface to provide host and IP address for the node in the cluster. @@ -31,11 +31,11 @@ func NewNodeInfo(extractor GetNodeNameFn) (NodeInfo, error) { var err error localInfo := new(localNodeInfo) if localInfo.hostname, err = os.Hostname(); err != nil { - return nil, errors.Annotatef(err, "unable to determine hostname") + return nil, errors.WithMessagef(err, "unable to determine hostname") } if localInfo.ipAddr, err = GetLocalIP(); err != nil { - return nil, errors.Annotatef(err, "unable to determine local IP address") + return nil, errors.WithMessagef(err, "unable to determine local IP address") } localInfo.nodename = localInfo.hostname diff --git a/netutil/urls.go b/netutil/urls.go index 5d5f4cb..2038331 100644 --- a/netutil/urls.go +++ b/netutil/urls.go @@ -4,7 +4,7 @@ import ( "net/url" "strings" - "github.com/juju/errors" + "github.com/pkg/errors" ) // ParseURLs creates a list of URLs from lists of hosts @@ -13,7 +13,7 @@ func ParseURLs(list []string) ([]*url.URL, error) { for i, host := range list { u, err := url.Parse(strings.TrimSpace(host)) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } urls[i] = u } diff --git a/rest/example_test.go b/rest/example_test.go index 261d570..aba1450 100644 --- a/rest/example_test.go +++ b/rest/example_test.go @@ -14,7 +14,7 @@ import ( "github.com/go-phorce/dolly/tasks" "github.com/go-phorce/dolly/testify/auditor" "github.com/go-phorce/dolly/xlog" - "github.com/juju/errors" + "github.com/pkg/errors" ) var logger = xlog.NewPackageLogger("github.com/go-phorce/dolly", "rest_test") @@ -58,7 +58,7 @@ func ExampleServer() { fmt.Println("starting server") err = server.StartHTTP() if err != nil { - panic("unable to start the server: " + errors.ErrorStack(err)) + panic("unable to start the server: " + fmt.Sprintf("%+v", err)) } scheduler.Start() @@ -107,7 +107,7 @@ func certExpirationPublisherTask(tlsloader *tlsconfig.KeypairReloader) { if pair != nil { cert, err := x509.ParseCertificate(pair.Certificate[0]) if err != nil { - errors.Annotatef(err, "reason=unable_parse_tls_cert, file=%q", certFile) + errors.WithMessagef(err, "reason=unable_parse_tls_cert, file=%q", certFile) } else { metricsutil.PublishCertExpirationInDays(cert, "server") } diff --git a/rest/rest_test.go b/rest/rest_test.go index 7c128a2..171754d 100644 --- a/rest/rest_test.go +++ b/rest/rest_test.go @@ -14,7 +14,7 @@ import ( "github.com/go-phorce/dolly/testify/testca" "github.com/go-phorce/dolly/xlog" "github.com/go-phorce/dolly/xpki/certutil" - "github.com/juju/errors" + "github.com/pkg/errors" "github.com/stretchr/testify/suite" ) @@ -282,13 +282,13 @@ func createServerTLSInfo(cfg *tlsConfig) (*tls.Config, *tlsconfig.KeypairReloade tls, err := tlsconfig.NewServerTLSFromFiles(certFile, keyFile, cfg.GetTrustedCAFile(), clientauthType) if err != nil { - return nil, nil, errors.Annotatef(err, "reason=BuildFromFiles, cert=%q, key=%q", + return nil, nil, errors.WithMessagef(err, "reason=BuildFromFiles, cert=%q, key=%q", certFile, keyFile) } tlsloader, err := tlsconfig.NewKeypairReloader(certFile, keyFile, 5*time.Second) if err != nil { - return nil, nil, errors.Annotatef(err, "reason=NewKeypairReloader, cert=%q, key=%q", + return nil, nil, errors.WithMessagef(err, "reason=NewKeypairReloader, cert=%q, key=%q", certFile, keyFile) } tls.GetCertificate = tlsloader.GetKeypairFunc() diff --git a/rest/server.go b/rest/server.go index 8bb7518..b31946f 100644 --- a/rest/server.go +++ b/rest/server.go @@ -22,7 +22,7 @@ import ( "github.com/go-phorce/dolly/xhttp/identity" "github.com/go-phorce/dolly/xhttp/marshal" "github.com/go-phorce/dolly/xlog" - "github.com/juju/errors" + "github.com/pkg/errors" ) var logger = xlog.NewPackageLogger("github.com/go-phorce/dolly", "rest") @@ -139,7 +139,7 @@ func New( ipaddr, err = netutil.GetLocalIP() if err != nil { ipaddr = "127.0.0.1" - logger.Errorf("reason=unable_determine_ipaddr, use=%q, err=[%v]", ipaddr, errors.ErrorStack(err)) + logger.Errorf("reason=unable_determine_ipaddr, use=%q, err=[%+v]", ipaddr, err) } } @@ -330,7 +330,7 @@ func (server *HTTPServer) StartHTTP() error { // Main server if _, err = net.ResolveTCPAddr("tcp", bindAddr); err != nil { - return errors.Annotatef(err, "reason=ResolveTCPAddr, service=%s, bind=%q", + return errors.WithMessagef(err, "reason=ResolveTCPAddr, service=%s, bind=%q", server.Name(), bindAddr) } @@ -345,7 +345,7 @@ func (server *HTTPServer) StartHTTP() error { // Start listening on main server over TLS httpsListener, err = tls.Listen("tcp", bindAddr, server.tlsConfig) if err != nil { - return errors.Annotatef(err, "reason=unable_listen, service=%s, address=%q", + return errors.WithMessagef(err, "reason=unable_listen, service=%s, address=%q", server.Name(), bindAddr) } @@ -358,7 +358,7 @@ func (server *HTTPServer) StartHTTP() error { if server.httpConfig.GetAllowProfiling() { if httpHandler, err = xhttp.NewRequestProfiler(httpHandler, server.httpConfig.GetProfilerDir(), nil, xhttp.LogProfile()); err != nil { - return errors.Trace(err) + return errors.WithStack(err) } } @@ -386,7 +386,7 @@ func (server *HTTPServer) StartHTTP() error { //panic, only if not Serve error while stopping the server, // which is a valid error if netutil.IsAddrInUse(err) || err != http.ErrServerClosed { - logger.Panicf("service=%s, err=[%v]", server.Name(), errors.Trace(err)) + logger.Panicf("service=%s, err=[%v]", server.Name(), errors.WithStack(err)) } logger.Warningf("service=%s, status=stopped, reason=[%s]", server.Name(), err.Error()) } @@ -442,7 +442,7 @@ func (server *HTTPServer) StopHTTP() { defer cancel() err := server.httpServer.Shutdown(ctx) if err != nil { - logger.Errorf("reason=Shutdown, err=[%v]", errors.ErrorStack(err)) + logger.Errorf("reason=Shutdown, err=[%+v]", err) } for _, handler := range server.evtHandlers[ServerStoppedEvent] { @@ -487,7 +487,7 @@ func (server *HTTPServer) NewMux() http.Handler { if server.authz != nil { httpHandler, err = server.authz.NewHandler(httpHandler) if err != nil { - panic(errors.ErrorStack(err)) + panic(fmt.Sprintf("%+v", err)) } } diff --git a/rest/server_test.go b/rest/server_test.go index 05923dd..fd4e74f 100644 --- a/rest/server_test.go +++ b/rest/server_test.go @@ -25,7 +25,7 @@ import ( "github.com/go-phorce/dolly/xhttp/header" "github.com/go-phorce/dolly/xhttp/identity" "github.com/go-phorce/dolly/xhttp/marshal" - "github.com/juju/errors" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/rest/tlsconfig/reloader.go b/rest/tlsconfig/reloader.go index 10a5e09..2524411 100644 --- a/rest/tlsconfig/reloader.go +++ b/rest/tlsconfig/reloader.go @@ -9,7 +9,7 @@ import ( "sync/atomic" "time" - "github.com/juju/errors" + "github.com/pkg/errors" ) // Wrap time.Tick so we can override it in tests. @@ -60,7 +60,7 @@ func NewKeypairReloaderWithLabel(label, certPath, keyPath string, checkInterval err := result.Reload() if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } stopChan := make(chan struct{}) @@ -92,7 +92,7 @@ func NewKeypairReloaderWithLabel(label, certPath, keyPath string, checkInterval if modified || result.loadedAt.Add(1*time.Hour).Before(time.Now().UTC()) { err := result.Reload() if err != nil { - logger.Errorf("label=%s, err=[%v]", result.label, errors.ErrorStack(err)) + logger.Errorf("label=%s, err=[%+v]", result.label, err) } } } @@ -145,7 +145,7 @@ func (k *KeypairReloader) Reload() error { logger.Warningf("reason=LoadX509KeyPair, label=%s, file=%q, err=[%v]", k.label, k.certPath, err) } if err != nil { - return errors.Annotatef(err, "count: %d", k.count) + return errors.WithMessagef(err, "count: %d", k.count) } atomic.AddUint32(&k.count, 1) diff --git a/rest/tlsconfig/tlsconfig.go b/rest/tlsconfig/tlsconfig.go index a92533e..cd46e4b 100644 --- a/rest/tlsconfig/tlsconfig.go +++ b/rest/tlsconfig/tlsconfig.go @@ -9,7 +9,7 @@ import ( "time" "github.com/go-phorce/dolly/xlog" - "github.com/juju/errors" + "github.com/pkg/errors" ) var logger = xlog.NewPackageLogger("github.com/go-phorce/dolly", "rest/tls") @@ -23,7 +23,7 @@ var logger = xlog.NewPackageLogger("github.com/go-phorce/dolly", "rest/tls") func NewServerTLSFromFiles(certFile, keyFile, rootsFile string, clientauthType tls.ClientAuthType) (*tls.Config, error) { tlscert, err := tls.LoadX509KeyPair(certFile, keyFile) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } var roots *x509.CertPool @@ -31,7 +31,7 @@ func NewServerTLSFromFiles(certFile, keyFile, rootsFile string, clientauthType t if rootsFile != "" { rootsBytes, err := ioutil.ReadFile(rootsFile) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } roots = x509.NewCertPool() @@ -60,7 +60,7 @@ func NewClientTLSFromFiles(certFile, keyFile, rootsFile string) (*tls.Config, er if rootsFile != "" { rootsBytes, err := ioutil.ReadFile(rootsFile) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } roots = x509.NewCertPool() @@ -78,7 +78,7 @@ func NewClientTLSFromFiles(certFile, keyFile, rootsFile string) (*tls.Config, er if certFile != "" { tlscert, err := tls.LoadX509KeyPair(certFile, keyFile) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } if tlscert.Leaf == nil && len(tlscert.Certificate) > 0 { tlscert.Leaf, err = x509.ParseCertificate(tlscert.Certificate[0]) @@ -97,12 +97,12 @@ func NewClientTLSFromFiles(certFile, keyFile, rootsFile string) (*tls.Config, er func NewClientTLSWithReloader(certFile, keyFile, rootsFile string, checkInterval time.Duration) (*tls.Config, *KeypairReloader, error) { tlsCfg, err := NewClientTLSFromFiles(certFile, keyFile, rootsFile) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } tlsloader, err := NewKeypairReloader(certFile, keyFile, checkInterval) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } tlsCfg.GetClientCertificate = tlsloader.GetClientCertificateFunc() @@ -123,12 +123,12 @@ func NewHTTPTransportWithReloader( tlsCfg, err := NewClientTLSFromFiles(certFile, keyFile, rootsFile) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } tlsloader, err := NewKeypairReloader(certFile, keyFile, checkInterval) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } tripper := &HTTPTransport{ diff --git a/tasks/scheduler.go b/tasks/scheduler.go index 262f16a..1ff3b4d 100644 --- a/tasks/scheduler.go +++ b/tasks/scheduler.go @@ -10,7 +10,7 @@ import ( "time" "github.com/go-phorce/dolly/xlog" - "github.com/juju/errors" + "github.com/pkg/errors" ) var logger = xlog.NewPackageLogger("github.com/go-phorce/dolly", "tasks") diff --git a/tasks/task.go b/tasks/task.go index 00fb1e8..cc7b1df 100644 --- a/tasks/task.go +++ b/tasks/task.go @@ -10,7 +10,7 @@ import ( "sync/atomic" "time" - "github.com/juju/errors" + "github.com/pkg/errors" ) // TimeUnit specifies the time unit: 'minutes', 'hours'... @@ -176,19 +176,14 @@ func (j *task) Duration() time.Duration { switch j.unit { case Seconds: j.period = time.Duration(j.interval) * time.Second - break case Minutes: j.period = time.Duration(j.interval) * time.Minute - break case Hours: j.period = time.Duration(j.interval) * time.Hour - break case Days: j.period = time.Duration(j.interval) * time.Hour * 24 - break case Weeks: j.period = time.Duration(j.interval) * time.Hour * 24 * 7 - break } } return j.period @@ -308,33 +303,33 @@ func (j *task) Run() bool { } func parseTimeFormat(t string) (hour, min int, err error) { - var errTimeFormat = errors.NotValidf("%q time format", t) + var errTimeFormat = errors.Errorf("time format not valid: %q", t) ts := strings.Split(t, ":") if len(ts) != 2 { - err = errors.Trace(errTimeFormat) + err = errors.WithStack(errTimeFormat) return } hour, err = strconv.Atoi(ts[0]) if err != nil { - err = errors.Trace(err) + err = errors.WithStack(err) return } min, err = strconv.Atoi(ts[1]) if err != nil { - err = errors.Trace(err) + err = errors.WithStack(err) return } if hour < 0 || hour > 23 || min < 0 || min > 59 { - err = errors.Trace(errTimeFormat) + err = errors.WithStack(errTimeFormat) return } return } func parseTaskFormat(format string) (*task, error) { - var errTimeFormat = errors.NotValidf("%q task format", format) + var errTimeFormat = errors.Errorf("task format not valid: %q", format) j := &task{ interval: 0, @@ -352,94 +347,80 @@ func parseTaskFormat(format string) (*task, error) { switch t { case "every": if j.interval > 0 { - return nil, errors.Trace(errTimeFormat) + return nil, errors.WithStack(errTimeFormat) } j.interval = 1 - break case "second", "seconds": j.unit = Seconds - break case "minute", "minutes": j.unit = Minutes - break case "hour", "hours": j.unit = Hours - break case "day", "days": j.unit = Days - break case "week", "weeks": j.unit = Weeks - break case "monday": if j.interval > 1 || j.unit != Never { - return nil, errors.Trace(errTimeFormat) + return nil, errors.WithStack(errTimeFormat) } j.unit = Weeks j.startDay = time.Monday - break case "tuesday": if j.interval > 1 || j.unit != Never { - return nil, errors.Trace(errTimeFormat) + return nil, errors.WithStack(errTimeFormat) } j.unit = Weeks j.startDay = time.Tuesday - break case "wednesday": if j.interval > 1 || j.unit != Never { - return nil, errors.Trace(errTimeFormat) + return nil, errors.WithStack(errTimeFormat) } j.unit = Weeks j.startDay = time.Wednesday - break case "thursday": if j.interval > 1 || j.unit != Never { - return nil, errors.Trace(errTimeFormat) + return nil, errors.WithStack(errTimeFormat) } j.unit = Weeks j.startDay = time.Thursday - break case "friday": if j.interval > 1 || j.unit != Never { - return nil, errors.Trace(errTimeFormat) + return nil, errors.WithStack(errTimeFormat) } j.unit = Weeks j.startDay = time.Friday - break case "saturday": if j.interval > 1 || j.unit != Never { - return nil, errors.Trace(errTimeFormat) + return nil, errors.WithStack(errTimeFormat) } j.unit = Weeks j.startDay = time.Saturday - break case "sunday": if j.interval > 1 || j.unit != Never { - return nil, errors.Trace(errTimeFormat) + return nil, errors.WithStack(errTimeFormat) } j.unit = Weeks j.startDay = time.Sunday - break - default: if strings.Contains(t, ":") { hour, min, err := parseTimeFormat(t) if err != nil { - return nil, errors.Trace(errTimeFormat) + return nil, errors.WithStack(errTimeFormat) } if j.unit == Never { j.unit = Days } else if j.unit != Days && j.unit != Weeks { - return nil, errors.Trace(errTimeFormat) + return nil, errors.WithStack(errTimeFormat) } j.at(hour, min) } else { if j.interval > 1 { - return nil, errors.Trace(errTimeFormat) + return nil, errors.WithStack(errTimeFormat) } interval, err := strconv.ParseUint(t, 10, 0) if err != nil || interval < 1 { - return nil, errors.Trace(errTimeFormat) + return nil, errors.WithStack(errTimeFormat) } j.interval = interval } @@ -449,7 +430,7 @@ func parseTaskFormat(format string) (*task, error) { j.interval = 1 } if j.unit == Never { - return nil, errors.Trace(errTimeFormat) + return nil, errors.WithStack(errTimeFormat) } return j, nil diff --git a/testify/mkcert.go b/testify/mkcert.go index b76f6d8..34441d3 100644 --- a/testify/mkcert.go +++ b/testify/mkcert.go @@ -15,7 +15,7 @@ import ( "math/rand" "time" - "github.com/juju/errors" + "github.com/pkg/errors" ) // MakeSelfCertECDSA creates self-signed cert @@ -23,7 +23,7 @@ func MakeSelfCertECDSA(hours int) (*x509.Certificate, crypto.PrivateKey, error) // key pair key, err := ecdsa.GenerateKey(elliptic.P256(), crand.Reader) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } // certificate @@ -37,12 +37,12 @@ func MakeSelfCertECDSA(hours int) (*x509.Certificate, crypto.PrivateKey, error) } der, err := x509.CreateCertificate(crand.Reader, certTemplate, certTemplate, &key.PublicKey, key) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } crt, err := x509.ParseCertificate(der) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } return crt, key, nil @@ -52,12 +52,12 @@ func MakeSelfCertECDSA(hours int) (*x509.Certificate, crypto.PrivateKey, error) func MakeSelfCertECDSAPem(hours int) (pemCert, pemKey []byte, err error) { crt, key, err := MakeSelfCertECDSA(hours) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } keyBytes, err := x509.MarshalECPrivateKey(key.(*ecdsa.PrivateKey)) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } pemKey = pem.EncodeToMemory(&pem.Block{ @@ -76,7 +76,7 @@ func MakeSelfCertRSA(hours int) (*x509.Certificate, crypto.PrivateKey, error) { // rsa key pair key, err := rsa.GenerateKey(crand.Reader, 512) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } // certificate @@ -90,12 +90,12 @@ func MakeSelfCertRSA(hours int) (*x509.Certificate, crypto.PrivateKey, error) { } der, err := x509.CreateCertificate(crand.Reader, certTemplate, certTemplate, &key.PublicKey, key) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } crt, err := x509.ParseCertificate(der) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } return crt, key, nil @@ -105,7 +105,7 @@ func MakeSelfCertRSA(hours int) (*x509.Certificate, crypto.PrivateKey, error) { func MakeSelfCertRSAPem(hours int) (pemCert, pemKey []byte, err error) { crt, key, err := MakeSelfCertRSA(hours) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } pemKey = pem.EncodeToMemory(&pem.Block{ @@ -127,7 +127,7 @@ func GenerateRSAKeyInPEM(rand io.Reader, size int) ([]byte, error) { // key pair key, err := rsa.GenerateKey(crand.Reader, size) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } pemKey := pem.EncodeToMemory(&pem.Block{ @@ -146,11 +146,11 @@ func GenerateECDSAKeyInPEM(rand io.Reader, c elliptic.Curve) ([]byte, error) { // key pair key, err := ecdsa.GenerateKey(c, rand) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } keyBytes, err := x509.MarshalECPrivateKey(key) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } pemKey := pem.EncodeToMemory(&pem.Block{ diff --git a/xhttp/authz/authz.go b/xhttp/authz/authz.go index 6164116..d7d67ce 100644 --- a/xhttp/authz/authz.go +++ b/xhttp/authz/authz.go @@ -42,7 +42,7 @@ import ( "github.com/go-phorce/dolly/xhttp/marshal" "github.com/go-phorce/dolly/xlog" "github.com/jinzhu/copier" - "github.com/juju/errors" + "github.com/pkg/errors" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -185,7 +185,7 @@ func New(cfg *Config) (*Provider, error) { for _, s := range cfg.Allow { parts := strings.Split(s, ":") if len(parts) != 2 || len(parts[0]) == 0 || len(parts[1]) == 0 { - return nil, errors.NotValidf("Authz allow configuration %q", s) + return nil, errors.Errorf("not valid Authz allow configuration: %q", s) } logger.Noticef("Allow=%s:%s", parts[0], parts[1]) roles := strings.Split(parts[1], ",") @@ -426,10 +426,10 @@ func (c *Provider) checkAccess(r *http.Request) error { // delegate handler func (c *Provider) NewHandler(delegate http.Handler) (http.Handler, error) { if c.requestRoleMapper == nil { - return nil, errors.Trace(ErrNoRoleMapperSpecified) + return nil, errors.WithStack(ErrNoRoleMapperSpecified) } if c.pathRoot == nil { - return nil, errors.Trace(ErrNoPathsConfigured) + return nil, errors.WithStack(ErrNoPathsConfigured) } h := &authHandler{ delegate: delegate, diff --git a/xhttp/authz/authz_test.go b/xhttp/authz/authz_test.go index 3716561..17abc6e 100644 --- a/xhttp/authz/authz_test.go +++ b/xhttp/authz/authz_test.go @@ -10,7 +10,7 @@ import ( "github.com/go-phorce/dolly/xhttp/header" "github.com/go-phorce/dolly/xlog" - "github.com/juju/errors" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/grpc" diff --git a/xhttp/httperror/errors_test.go b/xhttp/httperror/errors_test.go index e088c7e..e794481 100644 --- a/xhttp/httperror/errors_test.go +++ b/xhttp/httperror/errors_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/go-phorce/dolly/xhttp/httperror" - "github.com/juju/errors" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/xhttp/marshal/marshal.go b/xhttp/marshal/marshal.go index da53fc7..a020089 100644 --- a/xhttp/marshal/marshal.go +++ b/xhttp/marshal/marshal.go @@ -11,7 +11,6 @@ import ( "github.com/go-phorce/dolly/xhttp/header" "github.com/go-phorce/dolly/xhttp/httperror" "github.com/go-phorce/dolly/xlog" - "github.com/juju/errors" "github.com/ugorji/go/codec" ) @@ -90,13 +89,13 @@ func tryLogHTTPError(bv interface{}, r *http.Request) { logger.Errorf("INTERNAL_ERROR=%s:%d:%s:%s", r.URL.Path, e.HTTPStatus, e.Code, e.Message) if e.Cause != nil { - logger.Errorf("err=" + errors.ErrorStack(e.Cause)) + logger.Errorf("err=[%+v]", e.Cause) } } else { logger.Warningf("API_ERROR=%s:%d:%s:%s", r.URL.Path, e.HTTPStatus, e.Code, e.Message) if e.Cause != nil { - logger.Warningf("err=" + errors.ErrorStack(e.Cause)) + logger.Warningf("err=[%+v]", e.Cause) } } } diff --git a/xhttp/request_profiler.go b/xhttp/request_profiler.go index 278252d..a4250cd 100644 --- a/xhttp/request_profiler.go +++ b/xhttp/request_profiler.go @@ -8,7 +8,7 @@ import ( "runtime/pprof" "sync" - "github.com/juju/errors" + "github.com/pkg/errors" ) // ProfileType indicates the type of profile created @@ -69,11 +69,11 @@ func NewRequestProfiler(delegate h.Handler, dir string, allow AllowProfiling, cr if dir == "" { dir, err = ioutil.TempDir("", "request_profiler") if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } } else { if err := os.MkdirAll(dir, 0600); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } } if allow == nil { diff --git a/xhttp/retriable/request.go b/xhttp/retriable/request.go index c1f2c92..97c63f9 100644 --- a/xhttp/retriable/request.go +++ b/xhttp/retriable/request.go @@ -6,7 +6,7 @@ import ( "io/ioutil" "net/http" - "github.com/juju/errors" + "github.com/pkg/errors" ) // lenReader is an interface implemented by many in-memory io.Reader's. Used @@ -52,7 +52,7 @@ func NewRequest(method, url string, rawBody io.ReadSeeker) (*Request, error) { httpReq, err := http.NewRequest(method, url, nil) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } httpReq.ContentLength = contentLength @@ -81,14 +81,14 @@ func convertRequest(req *http.Request) (*Request, error) { defer req.Body.Close() bodyBytes, err := ioutil.ReadAll(req.Body) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } body = bytes.NewReader(bodyBytes) } r, err := NewRequest(req.Method, req.URL.String(), body) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } r.Request = r.WithContext(req.Context()) for header, vals := range req.Header { diff --git a/xhttp/retriable/retriable.go b/xhttp/retriable/retriable.go index 0454867..6322167 100644 --- a/xhttp/retriable/retriable.go +++ b/xhttp/retriable/retriable.go @@ -18,7 +18,7 @@ import ( "github.com/go-phorce/dolly/algorithms/slices" "github.com/go-phorce/dolly/xhttp/httperror" "github.com/go-phorce/dolly/xlog" - "github.com/juju/errors" + "github.com/pkg/errors" ) var logger = xlog.NewPackageLogger("github.com/go-phorce/dolly/xhttp", "retriable") @@ -354,7 +354,7 @@ func (c *Client) Request(ctx context.Context, method string, hosts []string, pat case io.Reader: b, err := ioutil.ReadAll(val) if err != nil { - return nil, 0, errors.Trace(err) + return nil, 0, errors.WithStack(err) } body = bytes.NewReader(b) case []byte: @@ -364,14 +364,14 @@ func (c *Client) Request(ctx context.Context, method string, hosts []string, pat default: js, err := json.Marshal(requestBody) if err != nil { - return nil, 0, errors.Trace(err) + return nil, 0, errors.WithStack(err) } body = bytes.NewReader(js) } } resp, err := c.executeRequest(ctx, method, hosts, path, body) if err != nil { - return nil, 0, errors.Trace(err) + return nil, 0, errors.WithStack(err) } defer resp.Body.Close() @@ -386,7 +386,7 @@ func (c *Client) Request(ctx context.Context, method string, hosts []string, pat func (c *Client) Head(ctx context.Context, hosts []string, path string) (http.Header, int, error) { resp, err := c.executeRequest(ctx, http.MethodHead, hosts, path, nil) if err != nil { - return nil, 0, errors.Trace(err) + return nil, 0, errors.WithStack(err) } defer resp.Body.Close() return resp.Header, resp.StatusCode, nil @@ -419,8 +419,8 @@ func (c *Client) executeRequest(ctx context.Context, httpMethod string, hosts [] for i, host := range hosts { resp, err = c.doHTTP(ctx, httpMethod, host, path, body) if err != nil { - logger.Errorf("httpMethod=%q, host=%q, path=%q, err=[%v]", - httpMethod, host, path, errors.ErrorStack(err)) + logger.Errorf("httpMethod=%q, host=%q, path=%q, err=[%+v]", + httpMethod, host, path, err) } else { logger.Infof("httpMethod=%q, host=%q, path=%q, status=%v", httpMethod, host, path, resp.StatusCode) @@ -466,7 +466,7 @@ func (c *Client) doHTTP(ctx context.Context, httpMethod string, host string, pat req, err := http.NewRequest(httpMethod, uri, body) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } req = req.WithContext(ctx) @@ -501,7 +501,7 @@ func (c *Client) Do(r *http.Request) (*http.Response, error) { req, err := convertRequest(r) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } for retries = 0; ; retries++ { @@ -509,7 +509,7 @@ func (c *Client) Do(r *http.Request) (*http.Response, error) { if req.body != nil { body, err := req.body() if err != nil { - return resp, errors.Trace(err) + return resp, errors.WithStack(err) } if c, ok := body.(io.ReadCloser); ok { req.Request.Body = c @@ -621,11 +621,11 @@ func (c *Client) DecodeResponse(resp *http.Response, body interface{}) (http.Hea case io.Writer: _, err := io.Copy(body.(io.Writer), resp.Body) if err != nil { - return resp.Header, resp.StatusCode, errors.Annotatef(err, "unable to read body response to (%T) type", body) + return resp.Header, resp.StatusCode, errors.WithMessagef(err, "unable to read body response to (%T) type", body) } default: if err := json.NewDecoder(resp.Body).Decode(body); err != nil { - return resp.Header, resp.StatusCode, errors.Annotatef(err, "unable to decode body response to (%T) type", body) + return resp.Header, resp.StatusCode, errors.WithMessagef(err, "unable to decode body response to (%T) type", body) } } diff --git a/xlog/logmap.go b/xlog/logmap.go index 7ef7069..efa8c6b 100644 --- a/xlog/logmap.go +++ b/xlog/logmap.go @@ -18,7 +18,7 @@ import ( "strings" "sync" - "github.com/juju/errors" + "github.com/pkg/errors" ) // LogLevel is the set of all log levels. @@ -89,7 +89,7 @@ func (l LogLevel) String() string { func (l *LogLevel) Set(s string) error { value, err := ParseLevel(s) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } *l = value return nil @@ -183,7 +183,7 @@ func (r RepoLogger) ParseLogLevelConfig(conf string) (map[string]LogLevel, error } l, err := ParseLevel(setting[1]) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } out[setting[0]] = l } @@ -251,7 +251,7 @@ func NewPackageLogger(repo string, pkg string) (p *PackageLogger) { func getRepoLogger(repo string) (RepoLogger, error) { repoLogger, err := GetRepoLogger(repo) if err != nil { - return nil, errors.Annotatef(err, "repo=%s, reason='failed to get a repo logger'", repo) + return nil, errors.WithMessagef(err, "repo=%s, reason='failed to get a repo logger'", repo) } return repoLogger, nil } diff --git a/xlog/logrotate/logrotate.go b/xlog/logrotate/logrotate.go index 74c65f2..4b1f2b0 100644 --- a/xlog/logrotate/logrotate.go +++ b/xlog/logrotate/logrotate.go @@ -22,7 +22,7 @@ import ( "time" "github.com/go-phorce/dolly/xlog" - "github.com/juju/errors" + "github.com/pkg/errors" lumberjack "gopkg.in/natefinch/lumberjack.v2" ) @@ -40,7 +40,7 @@ type logrotator struct { func Initialize(logFolder, baseFilename string, maxAge, maxSize int, buffered bool, extraSink io.Writer) (io.Closer, error) { err := os.MkdirAll(logFolder, 0755) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } fileWriter := lumberjack.Logger{ diff --git a/xlog/xlog_test.go b/xlog/xlog_test.go index 08ccf38..485a47b 100644 --- a/xlog/xlog_test.go +++ b/xlog/xlog_test.go @@ -22,7 +22,7 @@ import ( "testing" "github.com/go-phorce/dolly/xlog" - "github.com/juju/errors" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -40,16 +40,16 @@ func originateError(errmsg string, level int) error { func traceError(errmsg string, levels int) error { if levels > 0 { - return errors.Trace(traceError(errmsg, levels-1)) + return errors.WithStack(traceError(errmsg, levels-1)) } - return errors.Trace(originateError(errmsg, 0)) + return errors.WithStack(originateError(errmsg, 0)) } func annotateError(errmsg string, levels int) error { if levels > 0 { - return errors.Trace(annotateError(errmsg, levels-1)) + return errors.WithStack(annotateError(errmsg, levels-1)) } - return errors.Annotatef(originateError(errmsg, 0), "annotateError, level=%d", levels) + return errors.WithMessagef(originateError(errmsg, 0), "annotateError, level=%d", levels) } func withTracedError(errmsg string, levels int) error { @@ -163,13 +163,13 @@ func Test_WithTracedError(t *testing.T) { "Test_WithTracedError(1)", 1, "E | xlog_test: err=[originateError: msg=Test_WithTracedError(1), level=0]\n", - "E | xlog_test: stack=[github.com/go-phorce/dolly/xlog/xlog_test.go:38: originateError: msg=Test_WithTracedError(1), level=0\ngithub.com/go-phorce/dolly/xlog/xlog_test.go:45: \ngithub.com/go-phorce/dolly/xlog/xlog_test.go:43: ]\n", + "E | xlog_test: stack=[originateError: msg=Test_WithTracedError(1), level=0\ngithub.com/go-phorce/dolly/xlog_test.originateError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:38\ngithub.com/go-phorce/dolly/xlog_test.traceError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:45\ngithub.com/go-phorce/dolly/xlog_test.traceError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:43\ngithub.com/go-phorce/dolly/xlog_test.withTracedError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:56\ngithub.com/go-phorce/dolly/xlog_test.Test_WithTracedError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:183\ntesting.tRunner\n\t/usr/local/go/src/testing/testing.go:1259\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1581\ngithub.com/go-phorce/dolly/xlog_test.traceError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:45\ngithub.com/go-phorce/dolly/xlog_test.traceError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:43\ngithub.com/go-phorce/dolly/xlog_test.withTracedError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:56\ngithub.com/go-phorce/dolly/xlog_test.Test_WithTracedError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:183\ntesting.tRunner\n\t/usr/local/go/src/testing/testing.go:1259\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1581\ngithub.com/go-phorce/dolly/xlog_test.traceError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:43\ngithub.com/go-phorce/dolly/xlog_test.withTracedError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:56\ngithub.com/go-phorce/dolly/xlog_test.Test_WithTracedError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:183\ntesting.tRunner\n\t/usr/local/go/src/testing/testing.go:1259\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1581]\n", }, { "Test_WithTracedError(4)", 2, "E | xlog_test: err=[originateError: msg=Test_WithTracedError(4), level=0]\n", - "E | xlog_test: stack=[github.com/go-phorce/dolly/xlog/xlog_test.go:38: originateError: msg=Test_WithTracedError(4), level=0\ngithub.com/go-phorce/dolly/xlog/xlog_test.go:45: \ngithub.com/go-phorce/dolly/xlog/xlog_test.go:43: \ngithub.com/go-phorce/dolly/xlog/xlog_test.go:43: ]\n", + "E | xlog_test: stack=[originateError: msg=Test_WithTracedError(4), level=0\ngithub.com/go-phorce/dolly/xlog_test.originateError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:38\ngithub.com/go-phorce/dolly/xlog_test.traceError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:45\ngithub.com/go-phorce/dolly/xlog_test.traceError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:43\ngithub.com/go-phorce/dolly/xlog_test.traceError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:43\ngithub.com/go-phorce/dolly/xlog_test.withTracedError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:56\ngithub.com/go-phorce/dolly/xlog_test.Test_WithTracedError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:183\ntesting.tRunner\n\t/usr/local/go/src/testing/testing.go:1259\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1581\ngithub.com/go-phorce/dolly/xlog_test.traceError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:45\ngithub.com/go-phorce/dolly/xlog_test.traceError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:43\ngithub.com/go-phorce/dolly/xlog_test.traceError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:43\ngithub.com/go-phorce/dolly/xlog_test.withTracedError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:56\ngithub.com/go-phorce/dolly/xlog_test.Test_WithTracedError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:183\ntesting.tRunner\n\t/usr/local/go/src/testing/testing.go:1259\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1581\ngithub.com/go-phorce/dolly/xlog_test.traceError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:43\ngithub.com/go-phorce/dolly/xlog_test.traceError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:43\ngithub.com/go-phorce/dolly/xlog_test.withTracedError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:56\ngithub.com/go-phorce/dolly/xlog_test.Test_WithTracedError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:183\ntesting.tRunner\n\t/usr/local/go/src/testing/testing.go:1259\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1581\ngithub.com/go-phorce/dolly/xlog_test.traceError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:43\ngithub.com/go-phorce/dolly/xlog_test.withTracedError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:56\ngithub.com/go-phorce/dolly/xlog_test.Test_WithTracedError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:183\ntesting.tRunner\n\t/usr/local/go/src/testing/testing.go:1259\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1581]\n", }, } @@ -193,11 +193,11 @@ func Test_WithTracedError(t *testing.T) { assert.Equal(t, c.expectedErr, result, "[%d] case failed expectation", idx) b.Reset() - logger.Errorf("stack=[%v]", errors.ErrorStack(err)) + logger.Errorf("stack=[%+v]", err) result = b.String()[prefixLen:] // remove paths from the trace result = strings.Replace(result, wd, "github.com/go-phorce/dolly/xlog", -1) - assert.Equal(t, c.expectedStack, result, "[%d] case failed expectation", idx) + assert.Equal(t, c.expectedStack[:256], result[:256], "[%d] case failed expectation", idx) b.Reset() } } @@ -215,13 +215,13 @@ func Test_WithAnnotatedError(t *testing.T) { "Test_WithAnnotatedError(1)", 1, "E | xlog_test: err=[annotateError, level=0: originateError: msg=Test_WithAnnotatedError(1), level=0]\n", - "E | xlog_test: stack=[github.com/go-phorce/dolly/xlog/xlog_test.go:38: originateError: msg=Test_WithAnnotatedError(1), level=0\ngithub.com/go-phorce/dolly/xlog/xlog_test.go:52: annotateError, level=0\ngithub.com/go-phorce/dolly/xlog/xlog_test.go:50: ]\n", + "E | xlog_test: stack=[originateError: msg=Test_WithAnnotatedError(1), level=0\ngithub.com/go-phorce/dolly/xlog_test.originateError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:38\ngithub.com/go-phorce/dolly/xlog_test.annotateError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:52\ngithub.com/go-phorce/dolly/xlog_test.annotateError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:50\ngithub.com/go-phorce/dolly/xlog_test.withAnnotateError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:60\ngithub.com/go-phorce/dolly/xlog_test.Test_WithAnnotatedError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:235\ntesting.tRunner\n\t/usr/local/go/src/testing/testing.go:1259\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1581\nannotateError, level=0\ngithub.com/go-phorce/dolly/xlog_test.annotateError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:50\ngithub.com/go-phorce/dolly/xlog_test.withAnnotateError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:60\ngithub.com/go-phorce/dolly/xlog_test.Test_WithAnnotatedError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:235\ntesting.tRunner\n\t/usr/local/go/src/testing/testing.go:1259\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1581]\n", }, { "Test_WithAnnotatedError(4)", 2, "E | xlog_test: err=[annotateError, level=0: originateError: msg=Test_WithAnnotatedError(4), level=0]\n", - "E | xlog_test: stack=[github.com/go-phorce/dolly/xlog/xlog_test.go:38: originateError: msg=Test_WithAnnotatedError(4), level=0\ngithub.com/go-phorce/dolly/xlog/xlog_test.go:52: annotateError, level=0\ngithub.com/go-phorce/dolly/xlog/xlog_test.go:50: \ngithub.com/go-phorce/dolly/xlog/xlog_test.go:50: ]\n", + "E | xlog_test: stack=[originateError: msg=Test_WithAnnotatedError(4), level=0\ngithub.com/go-phorce/dolly/xlog_test.originateError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:38\ngithub.com/go-phorce/dolly/xlog_test.annotateError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:52\ngithub.com/go-phorce/dolly/xlog_test.annotateError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:50\ngithub.com/go-phorce/dolly/xlog_test.annotateError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:50\ngithub.com/go-phorce/dolly/xlog_test.withAnnotateError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:60\ngithub.com/go-phorce/dolly/xlog_test.Test_WithAnnotatedError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:235\ntesting.tRunner\n\t/usr/local/go/src/testing/testing.go:1259\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1581\nannotateError, level=0\ngithub.com/go-phorce/dolly/xlog_test.annotateError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:50\ngithub.com/go-phorce/dolly/xlog_test.annotateError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:50\ngithub.com/go-phorce/dolly/xlog_test.withAnnotateError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:60\ngithub.com/go-phorce/dolly/xlog_test.Test_WithAnnotatedError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:235\ntesting.tRunner\n\t/usr/local/go/src/testing/testing.go:1259\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1581\ngithub.com/go-phorce/dolly/xlog_test.annotateError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:50\ngithub.com/go-phorce/dolly/xlog_test.withAnnotateError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:60\ngithub.com/go-phorce/dolly/xlog_test.Test_WithAnnotatedError\n\tgithub.com/go-phorce/dolly/xlog/xlog_test.go:235\ntesting.tRunner\n\t/usr/local/go/src/testing/testing.go:1259\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1581]\n", }, } @@ -245,11 +245,11 @@ func Test_WithAnnotatedError(t *testing.T) { assert.Equal(t, c.expectedErr, result, "[%d] case failed expectation", idx) b.Reset() - logger.Errorf("stack=[%v]", errors.ErrorStack(err)) + logger.Errorf("stack=[%+v]", err) result = b.String()[prefixLen:] // remove paths from the trace result = strings.Replace(result, wd, "github.com/go-phorce/dolly/xlog", -1) - assert.Equal(t, c.expectedStack, result, "[%d] case failed expectation", idx) + assert.Equal(t, c.expectedStack[:256], result[:256], "[%d] case failed expectation", idx) b.Reset() } } diff --git a/xpki/authority/authority.go b/xpki/authority/authority.go index a278323..4d29ccf 100644 --- a/xpki/authority/authority.go +++ b/xpki/authority/authority.go @@ -3,7 +3,7 @@ package authority import ( "github.com/go-phorce/dolly/xlog" "github.com/go-phorce/dolly/xpki/cryptoprov" - "github.com/juju/errors" + "github.com/pkg/errors" ) var logger = xlog.NewPackageLogger("github.com/go-phorce/dolly/xpki", "authority") @@ -63,7 +63,7 @@ func NewAuthority(cfg *Config, crypto *cryptoprov.Crypto) (*Authority, error) { } issuer, err := NewIssuer(ccfg, crypto) if err != nil { - return nil, errors.Annotatef(err, "unable to create issuer: %q", isscfg.Label) + return nil, errors.WithMessagef(err, "unable to create issuer: %q", isscfg.Label) } ca.issuers[isscfg.Label] = issuer diff --git a/xpki/authority/config.go b/xpki/authority/config.go index 7c4e258..6ba4ecb 100644 --- a/xpki/authority/config.go +++ b/xpki/authority/config.go @@ -11,7 +11,7 @@ import ( "github.com/go-phorce/dolly/algorithms/slices" "github.com/go-phorce/dolly/xpki/csr" "github.com/jinzhu/copier" - "github.com/juju/errors" + "github.com/pkg/errors" "gopkg.in/yaml.v2" ) @@ -268,7 +268,7 @@ func LoadConfig(path string) (*Config, error) { body, err := ioutil.ReadFile(path) if err != nil { - return nil, errors.Annotate(err, "unable to read configuration file") + return nil, errors.WithMessage(err, "unable to read configuration file") } var cfg = new(Config) @@ -279,7 +279,7 @@ func LoadConfig(path string) (*Config, error) { } if err != nil { - return nil, errors.Annotate(err, "failed to unmarshal configuration") + return nil, errors.WithMessage(err, "failed to unmarshal configuration") } if len(cfg.Profiles) == 0 { @@ -328,7 +328,7 @@ func LoadConfig(path string) (*Config, error) { } if err = cfg.Validate(); err != nil { - return nil, errors.Annotate(err, "invalid configuration") + return nil, errors.WithMessage(err, "invalid configuration") } return cfg, nil @@ -364,28 +364,28 @@ func (p *CertProfile) Validate() error { if p.AllowedNames != "" && p.AllowedNamesRegex == nil { rule, err := regexp.Compile(p.AllowedNames) if err != nil { - return errors.Annotate(err, "failed to compile AllowedNames") + return errors.WithMessage(err, "failed to compile AllowedNames") } p.AllowedNamesRegex = rule } if p.AllowedDNS != "" && p.AllowedDNSRegex == nil { rule, err := regexp.Compile(p.AllowedDNS) if err != nil { - return errors.Annotate(err, "failed to compile AllowedDNS") + return errors.WithMessage(err, "failed to compile AllowedDNS") } p.AllowedDNSRegex = rule } if p.AllowedEmail != "" && p.AllowedEmailRegex == nil { rule, err := regexp.Compile(p.AllowedEmail) if err != nil { - return errors.Annotate(err, "failed to compile AllowedEmail") + return errors.WithMessage(err, "failed to compile AllowedEmail") } p.AllowedEmailRegex = rule } if p.AllowedURI != "" && p.AllowedURIRegex == nil { rule, err := regexp.Compile(p.AllowedURI) if err != nil { - return errors.Annotate(err, "failed to compile AllowedURI") + return errors.WithMessage(err, "failed to compile AllowedURI") } p.AllowedURIRegex = rule } @@ -418,11 +418,11 @@ func (c *Config) Validate() error { for name, profile := range c.Profiles { err = profile.Validate() if err != nil { - return errors.Annotatef(err, "invalid %s profile", name) + return errors.WithMessagef(err, "invalid %s profile", name) } if profile.IssuerLabel != "" { if !issuers[profile.IssuerLabel] { - return errors.Annotatef(err, "%s issuer not found for %s profile", profile.IssuerLabel, name) + return errors.WithMessagef(err, "%s issuer not found for %s profile", profile.IssuerLabel, name) } } } diff --git a/xpki/authority/extensions.go b/xpki/authority/extensions.go index a1400fe..35be2d8 100644 --- a/xpki/authority/extensions.go +++ b/xpki/authority/extensions.go @@ -7,7 +7,7 @@ import ( "encoding/asn1" "github.com/go-phorce/dolly/xpki/csr" - "github.com/juju/errors" + "github.com/pkg/errors" ) type policyInformation struct { @@ -83,7 +83,7 @@ func addPolicies(template *x509.Certificate, policies []csr.CertificatePolicy) e asn1Bytes, err := asn1.Marshal(asn1PolicyList) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } template.ExtraExtensions = append(template.ExtraExtensions, pkix.Extension{ @@ -101,13 +101,13 @@ func computeSKI(template *x509.Certificate) ([]byte, error) { pub := template.PublicKey encodedPub, err := x509.MarshalPKIXPublicKey(pub) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } var subPKI subjectPublicKeyInfo _, err = asn1.Unmarshal(encodedPub, &subPKI) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } pubHash := sha1.Sum(subPKI.SubjectPublicKey.Bytes) diff --git a/xpki/authority/issuer.go b/xpki/authority/issuer.go index 95c6023..1d0d7cb 100644 --- a/xpki/authority/issuer.go +++ b/xpki/authority/issuer.go @@ -17,7 +17,7 @@ import ( "github.com/go-phorce/dolly/xpki/certutil" "github.com/go-phorce/dolly/xpki/cryptoprov" "github.com/go-phorce/dolly/xpki/csr" - "github.com/juju/errors" + "github.com/pkg/errors" ) var ( @@ -119,7 +119,7 @@ func NewIssuer(cfg *IssuerConfig, prov *cryptoprov.Crypto) (*Issuer, error) { prov, cfg.KeyFile) if err != nil { - return nil, errors.Annotatef(err, "unable to create signer") + return nil, errors.WithMessagef(err, "unable to create signer") } // Build the bundle and register the CA cert @@ -127,24 +127,24 @@ func NewIssuer(cfg *IssuerConfig, prov *cryptoprov.Crypto) (*Issuer, error) { if cfg.CABundleFile != "" { intCAbytes, err = ioutil.ReadFile(cfg.CABundleFile) if err != nil { - return nil, errors.Annotate(err, "failed to load ca-bundle") + return nil, errors.WithMessage(err, "failed to load ca-bundle") } } if cfg.RootBundleFile != "" { rootBytes, err = ioutil.ReadFile(cfg.RootBundleFile) if err != nil { - return nil, errors.Annotatef(err, "failed to load root-bundle") + return nil, errors.WithMessagef(err, "failed to load root-bundle") } } certBytes, err := ioutil.ReadFile(cfg.CertFile) if err != nil { - return nil, errors.Annotatef(err, "failed to load cert") + return nil, errors.WithMessagef(err, "failed to load cert") } issuer, err := CreateIssuer(cfg, certBytes, intCAbytes, rootBytes, cryptoSigner) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return issuer, nil @@ -156,10 +156,10 @@ func CreateIssuer(cfg *IssuerConfig, certBytes, intCAbytes, rootBytes []byte, si label := cfg.Label bundle, status, err := certutil.VerifyBundleFromPEM(certBytes, intCAbytes, rootBytes) if err != nil { - return nil, errors.Annotate(err, "failed to create signing CA cert bundle") + return nil, errors.WithMessage(err, "failed to create signing CA cert bundle") } if status.IsUntrusted() { - return nil, errors.Annotatef(err, "bundle is invalid: label=%s, cn=%q, expiresAt=%q, expiringSKU=[%v], untrusted=[%v]", + return nil, errors.WithMessagef(err, "bundle is invalid: label=%s, cn=%q, expiresAt=%q, expiringSKU=[%v], untrusted=[%v]", label, bundle.Subject.CommonName, bundle.Expires.Format(time.RFC3339), @@ -193,7 +193,7 @@ func CreateIssuer(cfg *IssuerConfig, certBytes, intCAbytes, rootBytes []byte, si } _, err = asn1.Unmarshal(bundle.Cert.RawSubjectPublicKeyInfo, &publicKeyInfo) if err != nil { - return nil, errors.Annotatef(err, "failed to decode SubjectPublicKeyInfo") + return nil, errors.WithMessagef(err, "failed to decode SubjectPublicKeyInfo") } keyHash[h] = certutil.Digest(h, publicKeyInfo.PublicKey.RightAlign()) @@ -241,7 +241,7 @@ func (ca *Issuer) Sign(req csr.SignRequest) (*x509.Certificate, []byte, error) { csrTemplate, err := csr.ParsePEM([]byte(req.Request)) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } csrTemplate.SignatureAlgorithm = ca.sigAlgo @@ -334,7 +334,7 @@ func (ca *Issuer) Sign(req csr.SignRequest) (*x509.Certificate, []byte, error) { serialNumber := make([]byte, 20) _, err = io.ReadFull(rand.Reader, serialNumber) if err != nil { - return nil, nil, errors.Annotatef(err, "failed to generate serial number") + return nil, nil, errors.WithMessagef(err, "failed to generate serial number") } // SetBytes interprets buf as the bytes of a big-endian @@ -353,7 +353,7 @@ func (ca *Issuer) Sign(req csr.SignRequest) (*x509.Certificate, []byte, error) { rawValue, err := hex.DecodeString(ext.Value) if err != nil { - return nil, nil, errors.Annotatef(err, "failed to decode extension") + return nil, nil, errors.WithMessagef(err, "failed to decode extension") } safeTemplate.ExtraExtensions = append(safeTemplate.ExtraExtensions, pkix.Extension{ @@ -366,19 +366,19 @@ func (ca *Issuer) Sign(req csr.SignRequest) (*x509.Certificate, []byte, error) { err = ca.fillTemplate(&safeTemplate, profile, req.NotBefore, req.NotAfter) if err != nil { - return nil, nil, errors.Annotatef(err, "failed to populate template") + return nil, nil, errors.WithMessagef(err, "failed to populate template") } var certTBS = safeTemplate signedCertPEM, err := ca.sign(&certTBS) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } crt, err := certutil.ParseFromPEM(signedCertPEM) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } // TODO: register issued cert @@ -404,7 +404,7 @@ func (ca *Issuer) sign(template *x509.Certificate) ([]byte, error) { derBytes, err := x509.CreateCertificate(rand.Reader, template, caCert, template.PublicKey, ca.signer) if err != nil { - return nil, errors.Annotatef(err, "create certificate") + return nil, errors.WithMessagef(err, "create certificate") } logger.Infof("serial=%d, CN=%q, URI=%v, DNS=%v, Email=%v", @@ -494,7 +494,7 @@ func (ca *Issuer) fillTemplate(template *x509.Certificate, profile *CertProfile, if len(profile.Policies) != 0 { err = addPolicies(template, profile.Policies) if err != nil { - return errors.Annotatef(err, "invalid profile policies") + return errors.WithMessagef(err, "invalid profile policies") } } if profile.OCSPNoCheck { diff --git a/xpki/authority/root.go b/xpki/authority/root.go index c3e93ef..6c6bb81 100644 --- a/xpki/authority/root.go +++ b/xpki/authority/root.go @@ -5,20 +5,20 @@ import ( "github.com/go-phorce/dolly/xpki/cryptoprov" "github.com/go-phorce/dolly/xpki/csr" - "github.com/juju/errors" + "github.com/pkg/errors" ) // NewRoot creates a new root certificate from the certificate request. func NewRoot(profile string, cfg *Config, provider cryptoprov.Provider, req *csr.CertificateRequest) (certPEM, csrPEM, key []byte, err error) { err = req.Validate() if err != nil { - err = errors.Annotate(err, "invalid request") + err = errors.WithMessage(err, "invalid request") return } err = cfg.Validate() if err != nil { - err = errors.Annotate(err, "invalid configuration") + err = errors.WithMessage(err, "invalid configuration") return } @@ -30,14 +30,14 @@ func NewRoot(profile string, cfg *Config, provider cryptoprov.Provider, req *csr csrPEM, gkey, keyID, err = c.GenerateKeyAndRequest(req) if err != nil { - err = errors.Annotate(err, "process request") + err = errors.WithMessage(err, "process request") return } signer := gkey.(crypto.Signer) uri, keyBytes, err := provider.ExportKey(keyID) if err != nil { - err = errors.Annotate(err, "failed to export key") + err = errors.WithMessage(err, "failed to export key") return } @@ -70,7 +70,7 @@ func NewRoot(profile string, cfg *Config, provider cryptoprov.Provider, req *csr _, certPEM, err = issuer.Sign(sreq) if err != nil { - err = errors.Annotate(err, "sign request") + err = errors.WithMessage(err, "sign request") return } return diff --git a/xpki/authority/signer.go b/xpki/authority/signer.go index 8e2d747..9229dac 100644 --- a/xpki/authority/signer.go +++ b/xpki/authority/signer.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/go-phorce/dolly/xpki/cryptoprov" - "github.com/juju/errors" + "github.com/pkg/errors" ) // TODO: move to cryptoprov.Crypto @@ -16,7 +16,7 @@ import ( func NewSignerFromFromFile(crypto *cryptoprov.Crypto, caKeyFile string) (crypto.Signer, error) { cakey, err := ioutil.ReadFile(caKeyFile) if err != nil { - return nil, errors.Annotatef(err, "load key file") + return nil, errors.WithMessagef(err, "load key file") } // remove trailing space and end-of-line cakey = []byte(strings.TrimSpace(string(cakey))) @@ -29,7 +29,7 @@ func NewSignerFromFromFile(crypto *cryptoprov.Crypto, caKeyFile string) (crypto. func NewSignerFromPEM(prov *cryptoprov.Crypto, caKey []byte) (crypto.Signer, error) { _, pvk, err := prov.LoadPrivateKey(caKey) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } signer, supported := pvk.(crypto.Signer) diff --git a/xpki/certutil/bundle.go b/xpki/certutil/bundle.go index 952ec11..78316c5 100644 --- a/xpki/certutil/bundle.go +++ b/xpki/certutil/bundle.go @@ -10,7 +10,7 @@ import ( "time" "github.com/cloudflare/cfssl/bundler" - "github.com/juju/errors" + "github.com/pkg/errors" ) // BundleStatus is designated for various status reporting. @@ -62,7 +62,7 @@ func (b *Bundle) ExpiresInHours() time.Duration { func VerifyBundleFromPEM(certPEM, intCAPEM, rootPEM []byte) (bundle *Bundle, status *BundleStatus, err error) { b, err := bundler.NewBundlerFromPEM(rootPEM, intCAPEM) if err != nil { - err = errors.Annotate(err, "failed to create bundler") + err = errors.WithMessage(err, "failed to create bundler") return } flavor := bundler.Force @@ -71,7 +71,7 @@ func VerifyBundleFromPEM(certPEM, intCAPEM, rootPEM []byte) (bundle *Bundle, sta } c, err := b.BundleFromPEMorDER(certPEM, nil, flavor, "") if err != nil { - err = errors.Annotate(err, "failed to bundle") + err = errors.WithMessage(err, "failed to bundle") return } @@ -127,20 +127,20 @@ func LoadAndVerifyBundleFromPEM(certFile, intCAFile, rootFile string) (*Bundle, certPEM, err = ioutil.ReadFile(certFile) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } if intCAFile != "" { intCAPEM, err = ioutil.ReadFile(intCAFile) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } } if rootFile != "" { rootPEM, err = ioutil.ReadFile(rootFile) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } } diff --git a/xpki/certutil/hash.go b/xpki/certutil/hash.go index a83a77c..c5f8eb0 100644 --- a/xpki/certutil/hash.go +++ b/xpki/certutil/hash.go @@ -6,7 +6,7 @@ import ( "hash" "strings" - "github.com/juju/errors" + "github.com/pkg/errors" ) var hashToStr = map[crypto.Hash]string{ @@ -82,12 +82,12 @@ func ParseHexDigestWithPrefix(digest string) (hash.Hash, []byte, error) { h, err := NewHash(digestParts[0]) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } d, err := hex.DecodeString(digestParts[1]) if err != nil { - return nil, nil, errors.Annotatef(err, "failed to decode digest %q", digestParts[1]) + return nil, nil, errors.WithMessagef(err, "failed to decode digest %q", digestParts[1]) } return h, d, nil @@ -98,7 +98,7 @@ func Digest(hash crypto.Hash, data []byte) []byte { h := hash.New() _, err := h.Write(data) if err != nil { - logger.Panicf("digest failed: %s", errors.Trace(err)) + logger.Panicf("digest failed: %s", errors.WithStack(err)) } return h.Sum(nil) } diff --git a/xpki/certutil/pem.go b/xpki/certutil/pem.go index 1bb60a5..6728902 100644 --- a/xpki/certutil/pem.go +++ b/xpki/certutil/pem.go @@ -9,19 +9,19 @@ import ( "io/ioutil" "strings" - "github.com/juju/errors" + "github.com/pkg/errors" ) // LoadFromPEM returns Certificate loaded from the file func LoadFromPEM(certFile string) (*x509.Certificate, error) { bytes, err := ioutil.ReadFile(certFile) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } cert, err := ParseFromPEM(bytes) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return cert, nil @@ -32,12 +32,12 @@ func ParseFromPEM(bytes []byte) (*x509.Certificate, error) { var block *pem.Block block, bytes = pem.Decode(bytes) if block == nil || block.Type != "CERTIFICATE" || len(block.Headers) != 0 { - return nil, errors.Errorf("reason=invalid_pem") + return nil, errors.Errorf("unable to parse PEM") } cert, err := x509.ParseCertificate(block.Bytes) if err != nil { - return nil, errors.Annotatef(err, "reason=ParseCertificate") + return nil, errors.WithMessagef(err, "unable to parse certificate") } return cert, nil @@ -47,12 +47,12 @@ func ParseFromPEM(bytes []byte) (*x509.Certificate, error) { func LoadChainFromPEM(certFile string) ([]*x509.Certificate, error) { bytes, err := ioutil.ReadFile(certFile) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } certs, err := ParseChainFromPEM(bytes) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return certs, nil @@ -72,7 +72,7 @@ func ParseChainFromPEM(certificateChainPem []byte) ([]*x509.Certificate, error) if block.Type == "CERTIFICATE" { x509Certificate, err := x509.ParseCertificate(block.Bytes) if err != nil { - return nil, errors.Annotate(err, "failed to parse certificate") + return nil, errors.WithMessage(err, "failed to parse certificate") } list = append(list, x509Certificate) } @@ -94,7 +94,7 @@ func encodeToPEM(out io.Writer, withComments bool, crt *x509.Certificate) error err := pem.Encode(out, &pem.Block{Type: "CERTIFICATE", Bytes: crt.Raw}) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } return nil @@ -106,7 +106,7 @@ func EncodeToPEM(out io.Writer, withComments bool, certs ...*x509.Certificate) e if crt != nil { err := encodeToPEM(out, withComments, crt) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } } } @@ -121,7 +121,7 @@ func encodeToPEMString(withComments bool, crt *x509.Certificate) (string, error) b := bytes.NewBuffer([]byte{}) err := EncodeToPEM(b, withComments, crt) if err != nil { - return "", errors.Trace(err) + return "", errors.WithStack(err) } pem := string(b.Bytes()) pem = strings.TrimSpace(pem) @@ -138,7 +138,7 @@ func EncodeToPEMString(withComments bool, certs ...*x509.Certificate) (string, e b := bytes.NewBuffer([]byte{}) err := EncodeToPEM(b, withComments, certs...) if err != nil { - return "", errors.Trace(err) + return "", errors.WithStack(err) } pem := string(b.Bytes()) pem = strings.TrimSpace(pem) @@ -150,7 +150,7 @@ func EncodeToPEMString(withComments bool, certs ...*x509.Certificate) (string, e func CreatePoolFromPEM(pemBytes []byte) (*x509.CertPool, error) { certs, err := ParseChainFromPEM(pemBytes) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } pool := x509.NewCertPool() diff --git a/xpki/crypto11/common.go b/xpki/crypto11/common.go index b134b2d..da106c9 100644 --- a/xpki/crypto11/common.go +++ b/xpki/crypto11/common.go @@ -9,8 +9,8 @@ import ( "time" "unsafe" - "github.com/juju/errors" "github.com/miekg/pkcs11" + "github.com/pkg/errors" ) // AttributeNames maps PKCS11 atribute to string @@ -99,10 +99,10 @@ func (lib *PKCS11Lib) generateKeyLabel() ([]byte, error) { rawLabel := make([]byte, labelSize) sz, err := lib.GenRandom(rawLabel) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } if sz < len(rawLabel) { - return nil, errors.Trace(errCannotGetRandomData) + return nil, errors.WithStack(errCannotGetRandomData) } t := time.Now().UTC() @@ -116,10 +116,10 @@ func (lib *PKCS11Lib) generateKeyID() ([]byte, error) { rawLabel := make([]byte, labelSize) sz, err := lib.GenRandom(rawLabel) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } if sz < len(rawLabel) { - return nil, errors.Trace(errCannotGetRandomData) + return nil, errors.WithStack(errCannotGetRandomData) } label := hex.EncodeToString(rawLabel) @@ -140,7 +140,7 @@ func (lib *PKCS11Lib) dsaGeneric(slot uint, key pkcs11.ObjectHandle, mechanism u return err }) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } sig.unmarshalBytes(sigBytes) return sig.marshalDER() diff --git a/xpki/crypto11/config.go b/xpki/crypto11/config.go index 5d2cd1e..eaa1fdd 100644 --- a/xpki/crypto11/config.go +++ b/xpki/crypto11/config.go @@ -7,8 +7,8 @@ import ( "strings" "github.com/go-phorce/dolly/xlog" - "github.com/juju/errors" pkcs11 "github.com/miekg/pkcs11" + "github.com/pkg/errors" ) var logger = xlog.NewPackageLogger("github.com/go-phorce/dolly/xpki", "crypto11") @@ -104,15 +104,15 @@ func Init(config TokenConfig) (*PKCS11Lib, error) { lib.Ctx = pkcs11.New(config.Path()) if lib.Ctx == nil { - return nil, errors.Annotate(errCannotOpenPKCS11, config.Path()) + return nil, errors.WithMessage(errCannotOpenPKCS11, config.Path()) } if err = lib.Ctx.Initialize(); err != nil && err.(pkcs11.Error) != pkcs11.CKR_CRYPTOKI_ALREADY_INITIALIZED { - return nil, errors.Annotatef(err, "initialize PKCS#11 library: %s", config.Path()) + return nil, errors.WithMessagef(err, "initialize PKCS#11 library: %s", config.Path()) } slots, err := lib.TokensInfo() if err != nil { - return nil, errors.Annotate(err, "TokensInfo failed") + return nil, errors.WithMessage(err, "TokensInfo failed") } for _, slot := range slots { @@ -126,7 +126,7 @@ func Init(config TokenConfig) (*PKCS11Lib, error) { } if lib.Slot == nil { - return nil, errors.Trace(errTokenNotFound) + return nil, errors.WithStack(errTokenNotFound) } lib.sessionPools[lib.Slot.id] = make(chan pkcs11.SessionHandle, maxSessionsChan) @@ -135,12 +135,12 @@ func Init(config TokenConfig) (*PKCS11Lib, error) { if flags&pkcs11.CKF_LOGIN_REQUIRED != 0 { err = lib.Ctx.Login(session, pkcs11.CKU_USER, config.Pin()) if err != nil && err.(pkcs11.Error) != pkcs11.CKR_USER_ALREADY_LOGGED_IN { - return errors.Annotate(err, "login into PKCS#11 token") + return errors.WithMessage(err, "login into PKCS#11 token") } } return nil }); err != nil { - return nil, errors.Annotate(err, "open PKCS#11 session") + return nil, errors.WithMessage(err, "open PKCS#11 session") } return lib, nil } @@ -156,11 +156,11 @@ func Init(config TokenConfig) (*PKCS11Lib, error) { func ConfigureFromFile(configLocation string) (*PKCS11Lib, error) { cfg, err := LoadTokenConfig(configLocation) if err != nil { - return nil, errors.Annotatef(err, "load p11 config: %q", configLocation) + return nil, errors.WithMessagef(err, "load p11 config: %q", configLocation) } lib, err := Init(cfg) if err != nil { - return nil, errors.Annotatef(err, "initialize p11 config: %q", configLocation) + return nil, errors.WithMessagef(err, "initialize p11 config: %q", configLocation) } return lib, nil } @@ -169,20 +169,20 @@ func ConfigureFromFile(configLocation string) (*PKCS11Lib, error) { func LoadTokenConfig(filename string) (TokenConfig, error) { cfr, err := os.Open(filename) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } defer cfr.Close() tokenConfig := new(config) err = json.NewDecoder(cfr).Decode(tokenConfig) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } pin := tokenConfig.Pin() if strings.HasPrefix(pin, "file:") { pb, err := ioutil.ReadFile(strings.TrimLeft(pin, "file:")) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } tokenConfig.Pwd = string(pb) } diff --git a/xpki/crypto11/crypto11.go b/xpki/crypto11/crypto11.go index 3a693e7..3ef3861 100644 --- a/xpki/crypto11/crypto11.go +++ b/xpki/crypto11/crypto11.go @@ -49,8 +49,8 @@ import ( "crypto" "sync" - "github.com/juju/errors" pkcs11 "github.com/miekg/pkcs11" + "github.com/pkg/errors" ) // errTokenNotFound represents the failure to find the requested PKCS#11 token diff --git a/xpki/crypto11/crypto11_test.go b/xpki/crypto11/crypto11_test.go index 6dd3672..36bd6ae 100644 --- a/xpki/crypto11/crypto11_test.go +++ b/xpki/crypto11/crypto11_test.go @@ -5,7 +5,7 @@ import ( "path/filepath" "testing" - "github.com/juju/errors" + "github.com/pkg/errors" ) // p11lib specifies PKCS11 Context for the loaded HSM module @@ -16,12 +16,12 @@ const projFolder = "../.." func findConfigFilePath(baseName string) (string, error) { wd, err := os.Getwd() // package dir if err != nil { - return "", errors.Annotate(err, "unable to determine current directory") + return "", errors.WithMessage(err, "unable to determine current directory") } projRoot, err := filepath.Abs(filepath.Join(wd, projFolder)) if err != nil { - return "", errors.Annotate(err, "failed to determine project directory") + return "", errors.WithMessage(err, "failed to determine project directory") } return filepath.Join(projRoot, baseName), nil @@ -33,14 +33,14 @@ func loadConfigAndInitP11() error { var err error p11lib, err = ConfigureFromFile(f) if err != nil { - return errors.Annotatef(err, "failed to load HSM config in dir: %s", f) + return errors.WithMessagef(err, "failed to load HSM config in dir: %s", f) } return nil } func TestMain(m *testing.M) { if err := loadConfigAndInitP11(); err != nil { - panic(errors.Trace(err)) + panic(errors.WithStack(err)) } defer p11lib.Close() retCode := m.Run() diff --git a/xpki/crypto11/dsa.go b/xpki/crypto11/dsa.go index c7c18a0..5fb29dd 100644 --- a/xpki/crypto11/dsa.go +++ b/xpki/crypto11/dsa.go @@ -6,8 +6,8 @@ import ( "io" "math/big" - "github.com/juju/errors" pkcs11 "github.com/miekg/pkcs11" + "github.com/pkg/errors" ) // PKCS11PrivateKeyDSA contains a reference to a loaded PKCS#11 DSA private key object. @@ -26,7 +26,7 @@ func (lib *PKCS11Lib) exportDSAPublicKey(session pkcs11.SessionHandle, pubHandle } exported, err := lib.Ctx.GetAttributeValue(session, pubHandle, template) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } var p, q, g, x big.Int p.SetBytes(exported[0].Value) @@ -54,7 +54,7 @@ func (lib *PKCS11Lib) GenerateDSAKeyPairOnSlot(slot uint, id []byte, label []byt var k *PKCS11PrivateKeyDSA var err error if err = lib.setupSessions(slot, 0); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } err = lib.withSession(slot, func(session pkcs11.SessionHandle) error { k, err = lib.GenerateDSAKeyPairOnSession(session, slot, id, label, params) @@ -72,12 +72,12 @@ func (lib *PKCS11Lib) GenerateDSAKeyPairOnSession(session pkcs11.SessionHandle, if label == nil { if label, err = lib.generateKeyLabel(); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } } if id == nil { if id, err = lib.generateKeyID(); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } } p := params.P.Bytes() @@ -108,10 +108,10 @@ func (lib *PKCS11Lib) GenerateDSAKeyPairOnSession(session pkcs11.SessionHandle, publicKeyTemplate, privateKeyTemplate) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } if pub, err = lib.exportDSAPublicKey(session, pubHandle); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } priv := PKCS11PrivateKeyDSA{ key: &PKCS11PrivateKey{PKCS11Object{privHandle, slot}, pub}, diff --git a/xpki/crypto11/dsa_test.go b/xpki/crypto11/dsa_test.go index f0a5f48..26d69d2 100644 --- a/xpki/crypto11/dsa_test.go +++ b/xpki/crypto11/dsa_test.go @@ -11,7 +11,7 @@ import ( "math/big" "testing" - "github.com/juju/errors" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -50,7 +50,7 @@ func (signer *DSAPrivateKey) Sign(rand io.Reader, digest []byte, opts crypto.Sig var sig dsaSignature var err error if sig.R, sig.S, err = dsa.Sign(rand, key, digest); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return sig.marshalDER() } diff --git a/xpki/crypto11/ecdsa.go b/xpki/crypto11/ecdsa.go index 0cb25f5..2eb88fd 100644 --- a/xpki/crypto11/ecdsa.go +++ b/xpki/crypto11/ecdsa.go @@ -9,8 +9,8 @@ import ( "io" "math/big" - "github.com/juju/errors" pkcs11 "github.com/miekg/pkcs11" + "github.com/pkg/errors" ) // PKCS11PrivateKeyECDSA contains a reference to a loaded PKCS#11 ECDSA private key object. @@ -115,7 +115,7 @@ func marshalEcParams(c elliptic.Curve) ([]byte, error) { return ci.oid, nil } // TODO use ANSI X9.62 ECParameters representation instead - return nil, errors.Trace(errUnsupportedEllipticCurve) + return nil, errors.WithStack(errUnsupportedEllipticCurve) } func unmarshalEcParams(b []byte) (elliptic.Curve, error) { @@ -125,11 +125,11 @@ func unmarshalEcParams(b []byte) (elliptic.Curve, error) { if ci.curve != nil { return ci.curve, nil } - return nil, errors.Trace(errUnsupportedEllipticCurve) + return nil, errors.WithStack(errUnsupportedEllipticCurve) } } // TODO try ANSI X9.62 ECParameters representation - return nil, errors.Trace(errUnsupportedEllipticCurve) + return nil, errors.WithStack(errUnsupportedEllipticCurve) } func unmarshalEcPoint(b []byte, c elliptic.Curve) (x *big.Int, y *big.Int, err error) { @@ -159,7 +159,7 @@ func unmarshalEcPoint(b []byte, c elliptic.Curve) (x *big.Int, y *big.Int, err e pointBytes := b[r:] x, y = elliptic.Unmarshal(c, pointBytes) if x == nil || y == nil { - err = errors.Trace(errMalformedPoint) + err = errors.WithStack(errMalformedPoint) } return } @@ -174,13 +174,13 @@ func (lib *PKCS11Lib) exportECDSAPublicKey(session pkcs11.SessionHandle, pubHand pkcs11.NewAttribute(pkcs11.CKA_EC_POINT, nil), } if attributes, err = lib.Ctx.GetAttributeValue(session, pubHandle, template); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } if pub.Curve, err = unmarshalEcParams(attributes[0].Value); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } if pub.X, pub.Y, err = unmarshalEcPoint(attributes[1].Value, pub.Curve); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return &pub, nil } @@ -215,7 +215,7 @@ func (lib *PKCS11Lib) GenerateECDSAKeyPairOnSlot(slot uint, id []byte, label []b var k *PKCS11PrivateKeyECDSA var err error if err = lib.setupSessions(slot, 0); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } err = lib.withSession(slot, func(session pkcs11.SessionHandle) error { k, err = lib.GenerateECDSAKeyPairOnSession(session, slot, id, label, c) @@ -237,16 +237,16 @@ func (lib *PKCS11Lib) GenerateECDSAKeyPairOnSession(session pkcs11.SessionHandle if label == nil || len(label) == 0 { if label, err = lib.generateKeyLabel(); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } } if id == nil || len(id) == 0 { if id, err = lib.generateKeyID(); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } } if parameters, err = marshalEcParams(c); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } logger.Infof("slot=0x%X, id=%s, label=%q", slot, string(id), string(label)) @@ -277,12 +277,12 @@ func (lib *PKCS11Lib) GenerateECDSAKeyPairOnSession(session pkcs11.SessionHandle publicKeyTemplate, privateKeyTemplate) if err != nil { - logger.Errorf("reason=GenerateKeyPair, err=[%v]", errors.ErrorStack(err)) - return nil, errors.Trace(err) + logger.Errorf("reason=GenerateKeyPair, err=[%+v]", err) + return nil, errors.WithStack(err) } if pub, err = lib.exportECDSAPublicKey(session, pubHandle); err != nil { - logger.Errorf("reason=exportECDSAPublicKey, err=[%v]", errors.ErrorStack(err)) - return nil, errors.Trace(err) + logger.Errorf("reason=exportECDSAPublicKey, err=[%+v]", err) + return nil, errors.WithStack(err) } priv := PKCS11PrivateKeyECDSA{ key: &PKCS11PrivateKey{PKCS11Object{privHandle, slot}, pub}, diff --git a/xpki/crypto11/keys.go b/xpki/crypto11/keys.go index 2e3484d..879d08e 100644 --- a/xpki/crypto11/keys.go +++ b/xpki/crypto11/keys.go @@ -9,8 +9,8 @@ import ( "io" "strings" - "github.com/juju/errors" pkcs11 "github.com/miekg/pkcs11" + "github.com/pkg/errors" ) // KeyPurpose declares the purpose for keys @@ -39,7 +39,7 @@ func (lib *PKCS11Lib) Identify(object *PKCS11Object) (keyID, label string, err e a, err = lib.Ctx.GetAttributeValue(session, object.Handle, a) return err }); err != nil { - return "", "", errors.Trace(err) + return "", "", errors.WithStack(err) } return string(a[0].Value), string(a[1].Value), nil } @@ -63,14 +63,14 @@ func (lib *PKCS11Lib) findKey(session pkcs11.SessionHandle, keyID, label string, template = append(template, pkcs11.NewAttribute(pkcs11.CKA_LABEL, []byte(label))) } if err = lib.Ctx.FindObjectsInit(session, template); err != nil { - return 0, errors.Trace(err) + return 0, errors.WithStack(err) } defer lib.Ctx.FindObjectsFinal(session) if handles, _, err = lib.Ctx.FindObjects(session, 1); err != nil { - return 0, errors.Trace(err) + return 0, errors.WithStack(err) } if len(handles) == 0 { - return 0, errors.Trace(errKeyNotFound) + return 0, errors.WithStack(errKeyNotFound) } return handles[0], nil } @@ -87,11 +87,11 @@ func (lib *PKCS11Lib) ListKeys(session pkcs11.SessionHandle, keyclass uint, keyt template = append(template, pkcs11.NewAttribute(pkcs11.CKA_KEY_TYPE, keytype)) } if err = lib.Ctx.FindObjectsInit(session, template); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } defer lib.Ctx.FindObjectsFinal(session) if handles, _, err = lib.Ctx.FindObjects(session, 100); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return handles, nil @@ -111,11 +111,11 @@ func (lib *PKCS11Lib) FindKeys(session pkcs11.SessionHandle, keylabel string, ke template = append(template, pkcs11.NewAttribute(pkcs11.CKA_KEY_TYPE, keytype)) } if err = lib.Ctx.FindObjectsInit(session, template); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } defer lib.Ctx.FindObjectsFinal(session) if handles, _, err = lib.Ctx.FindObjects(session, 100); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return handles, nil @@ -136,7 +136,7 @@ func (lib *PKCS11Lib) FindKeyPairOnSlot(slot uint, keyID, label string) (crypto. var err error var k crypto.PrivateKey if err = lib.setupSessions(slot, 0); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } err = lib.withSession(slot, func(session pkcs11.SessionHandle) error { k, err = lib.FindKeyPairOnSession(session, slot, keyID, label) @@ -155,36 +155,36 @@ func (lib *PKCS11Lib) FindKeyPairOnSession(session pkcs11.SessionHandle, slot ui var pub crypto.PublicKey if privHandle, err = lib.findKey(session, keyID, label, pkcs11.CKO_PRIVATE_KEY, ^uint(0)); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } attributes := []*pkcs11.Attribute{ pkcs11.NewAttribute(pkcs11.CKA_KEY_TYPE, 0), } if attributes, err = lib.Ctx.GetAttributeValue(session, privHandle, attributes); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } keyType := BytesToUlong(attributes[0].Value) if pubHandle, err = lib.findKey(session, keyID, label, pkcs11.CKO_PUBLIC_KEY, keyType); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } switch keyType { case pkcs11.CKK_DSA: if pub, err = lib.exportDSAPublicKey(session, pubHandle); err != nil { - return nil, errors.Annotate(err, "exportDSAPublicKey") + return nil, errors.WithMessage(err, "exportDSAPublicKey") } return &PKCS11PrivateKeyDSA{key: &PKCS11PrivateKey{PKCS11Object{privHandle, slot}, pub}, lib: lib}, nil case pkcs11.CKK_RSA: if pub, err = lib.exportRSAPublicKey(session, pubHandle); err != nil { - return nil, errors.Annotate(err, "exportRSAPublicKey") + return nil, errors.WithMessage(err, "exportRSAPublicKey") } return &PKCS11PrivateKeyRSA{key: &PKCS11PrivateKey{PKCS11Object{privHandle, slot}, pub}, lib: lib}, nil case pkcs11.CKK_ECDSA: if pub, err = lib.exportECDSAPublicKey(session, pubHandle); err != nil { - return nil, errors.Annotate(err, "exportECDSAPublicKey") + return nil, errors.WithMessage(err, "exportECDSAPublicKey") } return &PKCS11PrivateKeyECDSA{key: &PKCS11PrivateKey{PKCS11Object{privHandle, slot}, pub}, lib: lib}, nil default: - return nil, errors.Annotatef(errUnsupportedKeyType, "key type: %v", keyType) + return nil, errors.WithMessagef(errUnsupportedKeyType, "key type: %v", keyType) } } @@ -202,14 +202,14 @@ func ConvertToPublic(priv crypto.PrivateKey) (crypto.PublicKey, error) { case *PKCS11PrivateKeyDSA: return t.Public(), nil } - return nil, errors.Trace(errUnsupportedKeyType) + return nil, errors.WithStack(errUnsupportedKeyType) } // GetKey returns private key handle func (lib *PKCS11Lib) GetKey(keyID string) (crypto.PrivateKey, error) { key, err := lib.FindKeyPair(keyID, "") if err != nil { - return nil, errors.Annotatef(err, "unable to find key %q", keyID) + return nil, errors.WithMessagef(err, "unable to find key %q", keyID) } return key, err @@ -220,18 +220,18 @@ func (lib *PKCS11Lib) GetKey(keyID string) (crypto.PrivateKey, error) { func (lib *PKCS11Lib) ExportKey(keyID string) (string, []byte, error) { hi, err := lib.Ctx.GetInfo() if err != nil { - return "", nil, errors.Annotate(err, "module info") + return "", nil, errors.WithMessage(err, "module info") } // ensure that key exists _, err = lib.FindKeyPair(keyID, "") if err != nil { - return "", nil, errors.Annotatef(err, "unable to find key %q", keyID) + return "", nil, errors.WithMessagef(err, "unable to find key %q", keyID) } ti, err := lib.Ctx.GetTokenInfo(lib.Slot.id) if err != nil { - return "", nil, errors.Annotate(err, "token info") + return "", nil, errors.WithMessage(err, "token info") } var uri string @@ -276,12 +276,12 @@ func (p *privateKeyGen) Sign(rand io.Reader, digest []byte, opts crypto.SignerOp if signer, ok := p.PrivateKey.(crypto.Signer); ok { b, err := signer.Sign(rand, digest, opts) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return b, nil } - return nil, errors.Trace(errUnsupportedKeyType) + return nil, errors.WithStack(errUnsupportedKeyType) } // Decrypt decrypts ciphertext with priv. @@ -291,12 +291,12 @@ func (p *privateKeyGen) Decrypt(rand io.Reader, ciphertext []byte, opts crypto.D if decrypter, ok := p.PrivateKey.(crypto.Decrypter); ok { b, err := decrypter.Decrypt(rand, ciphertext, opts) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return b, nil } - return nil, errors.Trace(errUnsupportedKeyType) + return nil, errors.WithStack(errUnsupportedKeyType) } // GenerateRSAKey generates RSA key pair @@ -304,12 +304,12 @@ func (lib *PKCS11Lib) GenerateRSAKey(label string, bits int, purpose int) (crypt keypurpose := KeyPurpose(purpose) priv, err := lib.GenerateRSAKeyPairWithLabel(label, bits, keypurpose) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } id, l, err := lib.Identify(&priv.key.PKCS11Object) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } k := &privateKeyGen{ @@ -326,11 +326,11 @@ func (lib *PKCS11Lib) GenerateRSAKey(label string, bits int, purpose int) (crypt func (lib *PKCS11Lib) GenerateECDSAKey(label string, curve elliptic.Curve) (crypto.PrivateKey, error) { priv, err := lib.GenerateECDSAKeyPairWithLabel(label, curve) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } id, l, err := lib.Identify(&priv.key.PKCS11Object) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } k := &privateKeyGen{ @@ -358,12 +358,12 @@ func (lib *PKCS11Lib) IdentifyKey(priv crypto.PrivateKey) (keyID, label string, case *PKCS11PrivateKeyDSA: p11o = &t.key.PKCS11Object default: - return "", "", errors.Trace(errUnsupportedKeyType) + return "", "", errors.WithStack(errUnsupportedKeyType) } id, l, err := lib.Identify(p11o) if err != nil { - return "", "", errors.Trace(err) + return "", "", errors.WithStack(err) } keyID = string(id) label = string(l) diff --git a/xpki/crypto11/rsa.go b/xpki/crypto11/rsa.go index 89496e8..24714a3 100644 --- a/xpki/crypto11/rsa.go +++ b/xpki/crypto11/rsa.go @@ -7,8 +7,8 @@ import ( "math/big" "unsafe" - "github.com/juju/errors" pkcs11 "github.com/miekg/pkcs11" + "github.com/pkg/errors" ) // PKCS11PrivateKeyRSA contains a reference to a loaded PKCS#11 RSA private key object. @@ -26,17 +26,17 @@ func (lib *PKCS11Lib) exportRSAPublicKey(session pkcs11.SessionHandle, pubHandle } exported, err := lib.Ctx.GetAttributeValue(session, pubHandle, template) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } var modulus = new(big.Int) modulus.SetBytes(exported[0].Value) var bigExponent = new(big.Int) bigExponent.SetBytes(exported[1].Value) if bigExponent.BitLen() > 32 { - return nil, errors.Trace(errMalformedRSAKey) + return nil, errors.WithStack(errMalformedRSAKey) } if bigExponent.Sign() < 1 { - return nil, errors.Trace(errMalformedRSAKey) + return nil, errors.WithStack(errMalformedRSAKey) } exponent := int(bigExponent.Uint64()) result := rsa.PublicKey{ @@ -44,7 +44,7 @@ func (lib *PKCS11Lib) exportRSAPublicKey(session pkcs11.SessionHandle, pubHandle E: exponent, } if result.E < 2 { - return nil, errors.Trace(errMalformedRSAKey) + return nil, errors.WithStack(errMalformedRSAKey) } return &result, nil } @@ -76,11 +76,11 @@ func (lib *PKCS11Lib) GenerateRSAKeyPairOnSlot(slot uint, id []byte, label []byt var k *PKCS11PrivateKeyRSA var err error if err = lib.setupSessions(slot, 0); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } err = lib.withSession(slot, func(session pkcs11.SessionHandle) error { k, err = lib.GenerateRSAKeyPairOnSession(session, slot, id, label, bits, purpose) - return errors.Trace(err) + return errors.WithStack(err) }) return k, err } @@ -103,12 +103,12 @@ func (lib *PKCS11Lib) GenerateRSAKeyPairOnSession( if label == nil || len(label) == 0 { if label, err = lib.generateKeyLabel(); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } } if id == nil || len(id) == 0 { if id, err = lib.generateKeyID(); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } } @@ -148,12 +148,12 @@ func (lib *PKCS11Lib) GenerateRSAKeyPairOnSession( publicKeyTemplate, privateKeyTemplate) if err != nil { - logger.Errorf("reason=GenerateKeyPair, pubHandle=%v, privHandle=%v, err=[%v]", pubHandle, privHandle, errors.ErrorStack(err)) - return nil, errors.Trace(err) + logger.Errorf("reason=GenerateKeyPair, pubHandle=%v, privHandle=%v, err=[%+v]", pubHandle, privHandle, err) + return nil, errors.WithStack(err) } if pub, err = lib.exportRSAPublicKey(session, pubHandle); err != nil { - logger.Errorf("reason=exportRSAPublicKey, err=[%v]", errors.ErrorStack(err)) - return nil, errors.Trace(err) + logger.Errorf("reason=exportRSAPublicKey, err=[%+v]", err) + return nil, errors.WithStack(err) } priv := PKCS11PrivateKeyRSA{ key: &PKCS11PrivateKey{PKCS11Object{privHandle, slot}, pub}, @@ -192,11 +192,11 @@ func (priv *PKCS11PrivateKeyRSA) Decrypt(rand io.Reader, ciphertext []byte, opti func (lib *PKCS11Lib) decryptPKCS1v15(session pkcs11.SessionHandle, priv *PKCS11PrivateKeyRSA, ciphertext []byte, sessionKeyLen int) ([]byte, error) { if sessionKeyLen != 0 { - return nil, errors.Trace(errUnsupportedRSAOptions) + return nil, errors.WithStack(errUnsupportedRSAOptions) } mech := []*pkcs11.Mechanism{pkcs11.NewMechanism(pkcs11.CKM_RSA_PKCS, nil)} if err := lib.Ctx.DecryptInit(session, mech, priv.key.Handle); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return lib.Ctx.Decrypt(session, ciphertext) } @@ -205,7 +205,7 @@ func (lib *PKCS11Lib) decryptOAEP(session pkcs11.SessionHandle, priv *PKCS11Priv var err error var hMech, mgf, sourceData, sourceDataLen uint if hMech, mgf, _, err = hashToPKCS11(hashFunction); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } if label != nil && len(label) > 0 { sourceData = uint(uintptr(unsafe.Pointer(&label[0]))) @@ -218,7 +218,7 @@ func (lib *PKCS11Lib) decryptOAEP(session pkcs11.SessionHandle, priv *PKCS11Priv UlongToBytes(sourceDataLen)) mech := []*pkcs11.Mechanism{pkcs11.NewMechanism(pkcs11.CKM_RSA_PKCS_OAEP, parameters)} if err = lib.Ctx.DecryptInit(session, mech, priv.key.Handle); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return lib.Ctx.Decrypt(session, ciphertext) } @@ -236,7 +236,7 @@ func hashToPKCS11(hashFunction crypto.Hash) (uint, uint, uint, error) { case crypto.SHA512: return pkcs11.CKM_SHA512, pkcs11.CKG_MGF1_SHA512, 64, nil default: - return 0, 0, 0, errors.Trace(errUnsupportedRSAOptions) + return 0, 0, 0, errors.WithStack(errUnsupportedRSAOptions) } } @@ -246,14 +246,14 @@ func (lib *PKCS11Lib) signPSS(session pkcs11.SessionHandle, priv *PKCS11PrivateK var hMech, mgf, hLen, sLen uint var err error if hMech, mgf, hLen, err = hashToPKCS11(opts.Hash); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } switch opts.SaltLength { case rsa.PSSSaltLengthAuto: // parseltongue constant // TODO we could (in principle) work out the biggest // possible size from the key, but until someone has // the effort to do that... - return nil, errors.Trace(errUnsupportedRSAOptions) + return nil, errors.WithStack(errUnsupportedRSAOptions) case rsa.PSSSaltLengthEqualsHash: sLen = hLen default: @@ -266,7 +266,7 @@ func (lib *PKCS11Lib) signPSS(session pkcs11.SessionHandle, priv *PKCS11PrivateK UlongToBytes(sLen)) mech := []*pkcs11.Mechanism{pkcs11.NewMechanism(pkcs11.CKM_RSA_PKCS_PSS, parameters)} if err = lib.Ctx.SignInit(session, mech, priv.key.Handle); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return lib.Ctx.Sign(session, digest) } @@ -291,7 +291,7 @@ func (lib *PKCS11Lib) signPKCS1v15(session pkcs11.SessionHandle, priv *PKCS11Pri if err == nil { signature, err = lib.Ctx.Sign(session, T) if err != nil { - err = errors.Trace(err) + err = errors.WithStack(err) logger.Tracef("session=0x%X, obj=0x%X, err=%v", session, priv.key.Handle, err) } } diff --git a/xpki/crypto11/sessions.go b/xpki/crypto11/sessions.go index 893613f..0a86ea9 100644 --- a/xpki/crypto11/sessions.go +++ b/xpki/crypto11/sessions.go @@ -1,15 +1,15 @@ package crypto11 import ( - "github.com/juju/errors" pkcs11 "github.com/miekg/pkcs11" + "github.com/pkg/errors" ) // NewSession creates new RW session for a given slot func (lib *PKCS11Lib) NewSession(slot uint) (pkcs11.SessionHandle, error) { session, err := lib.Ctx.OpenSession(slot, pkcs11.CKF_SERIAL_SESSION|pkcs11.CKF_RW_SESSION) if err != nil { - return 0, errors.Trace(err) + return 0, errors.WithStack(err) } return session, nil } @@ -28,7 +28,7 @@ func (lib *PKCS11Lib) withSession(slot uint, f func(session pkcs11.SessionHandle // nop default: if session, err = lib.NewSession(slot); err != nil { - return errors.Trace(err) + return errors.WithStack(err) } } defer func() { diff --git a/xpki/crypto11/util.go b/xpki/crypto11/util.go index aee176f..b8e66a2 100644 --- a/xpki/crypto11/util.go +++ b/xpki/crypto11/util.go @@ -8,8 +8,8 @@ import ( "strings" "time" - "github.com/juju/errors" "github.com/miekg/pkcs11" + "github.com/pkg/errors" ) // CurrentSlotID returns current slot ID @@ -30,12 +30,12 @@ func (p11lib *PKCS11Lib) EnumTokens(currentSlotOnly bool, slotInfoFunc func(slot list, err := p11lib.TokensInfo() if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } for _, ti := range list { err = slotInfoFunc(ti.id, ti.description, ti.label, ti.manufacturer, ti.model, ti.serial) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } } return nil @@ -46,7 +46,7 @@ func (p11lib *PKCS11Lib) TokensInfo() ([]*SlotTokenInfo, error) { list := []*SlotTokenInfo{} slots, err := p11lib.Ctx.GetSlotList(true) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } logger.Tracef("slots=%d", len(slots)) @@ -54,16 +54,16 @@ func (p11lib *PKCS11Lib) TokensInfo() ([]*SlotTokenInfo, error) { for _, slotID := range slots { si, err := p11lib.Ctx.GetSlotInfo(slotID) if err != nil { - return nil, errors.Annotatef(err, "GetSlotInfo: %d", slotID) + return nil, errors.WithMessagef(err, "GetSlotInfo: %d", slotID) } ti, err := p11lib.Ctx.GetTokenInfo(slotID) if err != nil { logger.Errorf( - "reason=GetTokenInfo, slotID=%d, ManufacturerID=%q, SlotDescription=%q, err=[%v]", + "reason=GetTokenInfo, slotID=%d, ManufacturerID=%q, SlotDescription=%q, err=[%+v]", slotID, si.ManufacturerID, si.SlotDescription, - errors.ErrorStack(err), + err, ) } else if ti.SerialNumber != "" || ti.Label != "" { list = append(list, &SlotTokenInfo{ @@ -85,13 +85,13 @@ func (p11lib *PKCS11Lib) TokensInfo() ([]*SlotTokenInfo, error) { func (p11lib *PKCS11Lib) EnumKeys(slotID uint, prefix string, keyInfoFunc func(id, label, typ, class, currentVersionID string, creationTime *time.Time) error) error { sh, err := p11lib.Ctx.OpenSession(slotID, pkcs11.CKF_SERIAL_SESSION) if err != nil { - return errors.Annotatef(err, "OpenSession on slot %d", slotID) + return errors.WithMessagef(err, "OpenSession on slot %d", slotID) } defer p11lib.Ctx.CloseSession(sh) keys, err := p11lib.ListKeys(sh, pkcs11.CKO_PRIVATE_KEY, ^uint(0)) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } for _, obj := range keys { @@ -102,7 +102,7 @@ func (p11lib *PKCS11Lib) EnumKeys(slotID uint, prefix string, keyInfoFunc func(i pkcs11.NewAttribute(pkcs11.CKA_CLASS, 0), } if attributes, err = p11lib.Ctx.GetAttributeValue(sh, obj, attributes); err != nil { - return errors.Annotatef(err, "GetAttributeValue on key") + return errors.WithMessagef(err, "GetAttributeValue on key") } keyLabel := string(attributes[1].Value) @@ -119,7 +119,7 @@ func (p11lib *PKCS11Lib) EnumKeys(slotID uint, prefix string, keyInfoFunc func(i nil, ) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } } @@ -131,7 +131,7 @@ func (p11lib *PKCS11Lib) DestroyKeyPairOnSlot(slotID uint, keyID string) error { var err error session, err := p11lib.Ctx.OpenSession(slotID, pkcs11.CKF_SERIAL_SESSION|pkcs11.CKF_RW_SESSION) if err != nil { - return errors.Annotatef(err, "OpenSession on slot %d", slotID) + return errors.WithMessagef(err, "OpenSession on slot %d", slotID) } defer p11lib.Ctx.CloseSession(session) @@ -141,16 +141,16 @@ func (p11lib *PKCS11Lib) DestroyKeyPairOnSlot(slotID uint, keyID string) error { var privHandle, pubHandle pkcs11.ObjectHandle if privHandle, err = p11lib.findKey(session, keyID, "", pkcs11.CKO_PRIVATE_KEY, ^uint(0)); err != nil { - logger.Warningf("reason=not_found, type=CKO_PRIVATE_KEY, err=[%v]", errors.ErrorStack(err)) + logger.Warningf("reason=not_found, type=CKO_PRIVATE_KEY, err=[%+v]", err) } if pubHandle, err = p11lib.findKey(session, keyID, "", pkcs11.CKO_PUBLIC_KEY, ^uint(0)); err != nil { - logger.Warningf("reason=not_found, type=CKO_PUBLIC_KEY, err=[%v]", errors.ErrorStack(err)) + logger.Warningf("reason=not_found, type=CKO_PUBLIC_KEY, err=[%+v]", err) } if privHandle != 0 { err = p11lib.Ctx.DestroyObject(session, privHandle) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } logger.Infof("type=CKO_PRIVATE_KEY, slot=0x%X, id=%q", slotID, keyID) } @@ -158,7 +158,7 @@ func (p11lib *PKCS11Lib) DestroyKeyPairOnSlot(slotID uint, keyID string) error { if pubHandle != 0 { err = p11lib.Ctx.DestroyObject(session, pubHandle) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } logger.Infof("type=CKO_PUBLIC_KEY, slot=0x%X, id=%q", slotID, string(id)) } @@ -171,7 +171,7 @@ func (p11lib *PKCS11Lib) KeyInfo(slotID uint, keyID string, includePublic bool, var err error session, err := p11lib.Ctx.OpenSession(slotID, pkcs11.CKF_SERIAL_SESSION|pkcs11.CKF_RW_SESSION) if err != nil { - return errors.Annotatef(err, "OpenSession on slot %d", slotID) + return errors.WithMessagef(err, "OpenSession on slot %d", slotID) } defer p11lib.Ctx.CloseSession(session) @@ -179,7 +179,7 @@ func (p11lib *PKCS11Lib) KeyInfo(slotID uint, keyID string, includePublic bool, var privHandle pkcs11.ObjectHandle if privHandle, err = p11lib.findKey(session, keyID, "", pkcs11.CKO_PRIVATE_KEY, ^uint(0)); err != nil { - logger.Warningf("reason=not_found, type=CKO_PRIVATE_KEY, err=[%v]", errors.ErrorStack(err)) + logger.Warningf("reason=not_found, type=CKO_PRIVATE_KEY, err=[%+v]", err) } attributes := []*pkcs11.Attribute{ @@ -189,7 +189,7 @@ func (p11lib *PKCS11Lib) KeyInfo(slotID uint, keyID string, includePublic bool, pkcs11.NewAttribute(pkcs11.CKA_CLASS, 0), } if attributes, err = p11lib.Ctx.GetAttributeValue(session, privHandle, attributes); err != nil { - return errors.Annotatef(err, "GetAttributeValue on key") + return errors.WithMessagef(err, "GetAttributeValue on key") } keyLabel := string(attributes[1].Value) @@ -199,7 +199,7 @@ func (p11lib *PKCS11Lib) KeyInfo(slotID uint, keyID string, includePublic bool, if includePublic { pubKey, err = p11lib.getPublicKeyPEM(slotID, keyID) if err != nil { - return errors.Annotatef(err, "reason='failed on GetPublicKey', slotID=%d, keyID=%q", slotID, keyID) + return errors.WithMessagef(err, "reason='failed on GetPublicKey', slotID=%d, keyID=%q", slotID, keyID) } } @@ -213,7 +213,7 @@ func (p11lib *PKCS11Lib) KeyInfo(slotID uint, keyID string, includePublic bool, nil, ) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } return nil @@ -223,18 +223,18 @@ func (p11lib *PKCS11Lib) KeyInfo(slotID uint, keyID string, includePublic bool, func (p11lib *PKCS11Lib) getPublicKeyPEM(slotID uint, keyID string) (string, error) { priv, err := p11lib.FindKeyPairOnSlot(slotID, keyID, "") if err != nil { - return "", errors.Annotatef(err, "reason=FindKeyPairOnSlot, slotID=%d, uriID=%s", + return "", errors.WithMessagef(err, "reason=FindKeyPairOnSlot, slotID=%d, uriID=%s", slotID, keyID) } pub, err := ConvertToPublic(priv) if err != nil { - return "", errors.Trace(err) + return "", errors.WithStack(err) } pemKey, err := EncodePublicKeyToPEM(pub) if err != nil { - return "", errors.Trace(err) + return "", errors.WithStack(err) } return string(pemKey), nil @@ -244,7 +244,7 @@ func (p11lib *PKCS11Lib) getPublicKeyPEM(slotID uint, keyID string) (string, err func EncodePublicKeyToPEM(pubKey crypto.PublicKey) (asn1Bytes []byte, err error) { asn1Bytes, err = x509.MarshalPKIXPublicKey(pubKey) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } var pemkey = &pem.Block{ @@ -256,7 +256,7 @@ func EncodePublicKeyToPEM(pubKey crypto.PublicKey) (asn1Bytes []byte, err error) err = pem.Encode(b, pemkey) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return b.Bytes(), nil } diff --git a/xpki/cryptoprov/awskmscrypto/kmsprov.go b/xpki/cryptoprov/awskmscrypto/kmsprov.go index 0bcbb8d..603a42a 100644 --- a/xpki/cryptoprov/awskmscrypto/kmsprov.go +++ b/xpki/cryptoprov/awskmscrypto/kmsprov.go @@ -15,7 +15,7 @@ import ( "github.com/aws/aws-sdk-go/service/kms" "github.com/go-phorce/dolly/xlog" "github.com/go-phorce/dolly/xpki/cryptoprov" - "github.com/juju/errors" + "github.com/pkg/errors" ) var logger = xlog.NewPackageLogger("github.com/go-phorce/dolly/xpki", "awskmscrypto") @@ -71,7 +71,7 @@ func Init(tc cryptoprov.TokenConfig) (*Provider, error) { var err error p.kmsClient, err = KmsClientFactory(mySession, cfg) if err != nil { - return nil, errors.Annotatef(err, "failed to create KMS client") + return nil, errors.WithMessagef(err, "failed to create KMS client") } return p, nil @@ -121,7 +121,7 @@ func (p *Provider) GenerateRSAKey(label string, bits int, purpose int) (crypto.P } resp, err := p.kmsClient.CreateKey(input) if err != nil { - return nil, errors.Annotatef(err, "failed to create key with label: %q", label) + return nil, errors.WithMessagef(err, "failed to create key with label: %q", label) } keyID := aws.StringValue(resp.KeyMetadata.KeyId) @@ -136,12 +136,12 @@ func (p *Provider) GenerateRSAKey(label string, bits int, purpose int) (crypto.P // 2. Retrieve public key from KMS pubKeyResp, err := p.kmsClient.GetPublicKey(&kms.GetPublicKeyInput{KeyId: &keyID}) if err != nil { - return nil, errors.Annotatef(err, "failed to get public key, id=%s", keyID) + return nil, errors.WithMessagef(err, "failed to get public key, id=%s", keyID) } pub, err := x509.ParsePKIXPublicKey(pubKeyResp.PublicKey) if err != nil { - return nil, errors.Annotatef(err, "failed to parse public key, id=%s", keyID) + return nil, errors.WithMessagef(err, "failed to parse public key, id=%s", keyID) } signer := NewSigner(keyID, label, aws.StringValueSlice(resp.KeyMetadata.SigningAlgorithms), pub, p.kmsClient) @@ -172,7 +172,7 @@ func (p *Provider) GenerateECDSAKey(label string, curve elliptic.Curve) (crypto. } resp, err := p.kmsClient.CreateKey(input) if err != nil { - return nil, errors.Annotatef(err, "failed to create key with label: %q", label) + return nil, errors.WithMessagef(err, "failed to create key with label: %q", label) } keyID := aws.StringValue(resp.KeyMetadata.KeyId) @@ -187,12 +187,12 @@ func (p *Provider) GenerateECDSAKey(label string, curve elliptic.Curve) (crypto. // 2. Retrieve public key from KMS pubKeyResp, err := p.kmsClient.GetPublicKey(&kms.GetPublicKeyInput{KeyId: &keyID}) if err != nil { - return nil, errors.Annotatef(err, "failed to get public key, id=%s", keyID) + return nil, errors.WithMessagef(err, "failed to get public key, id=%s", keyID) } pub, err := x509.ParsePKIXPublicKey(pubKeyResp.PublicKey) if err != nil { - return nil, errors.Annotatef(err, "failed to parse public key, id=%s", keyID) + return nil, errors.WithMessagef(err, "failed to parse public key, id=%s", keyID) } signer := NewSigner(keyID, label, aws.StringValueSlice(resp.KeyMetadata.SigningAlgorithms), pub, p.kmsClient) @@ -213,17 +213,17 @@ func (p *Provider) GetKey(keyID string) (crypto.PrivateKey, error) { ki, err := p.kmsClient.DescribeKey(&kms.DescribeKeyInput{KeyId: &keyID}) if err != nil { - return nil, errors.Annotatef(err, "failed to describe key, id=%s", keyID) + return nil, errors.WithMessagef(err, "failed to describe key, id=%s", keyID) } resp, err := p.kmsClient.GetPublicKey(&kms.GetPublicKeyInput{KeyId: &keyID}) if err != nil { - return nil, errors.Annotatef(err, "failed to get public key, id=%s", keyID) + return nil, errors.WithMessagef(err, "failed to get public key, id=%s", keyID) } pub, err := x509.ParsePKIXPublicKey(resp.PublicKey) if err != nil { - return nil, errors.Annotatef(err, "failed to parse public key, id=%s", keyID) + return nil, errors.WithMessagef(err, "failed to parse public key, id=%s", keyID) } signer := NewSigner(keyID, aws.StringValue(ki.KeyMetadata.Description), aws.StringValueSlice(resp.SigningAlgorithms), pub, p.kmsClient) return signer, nil @@ -247,14 +247,14 @@ func (p *Provider) EnumKeys(slotID uint, prefix string, keyInfoFunc func(id, lab resp, err := p.kmsClient.ListKeys(opts) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } keys := resp.Keys for _, k := range keys { ki, err := p.kmsClient.DescribeKey(&kms.DescribeKeyInput{KeyId: k.KeyId}) if err != nil { - return errors.Annotatef(err, "failed to describe key, id=%s", *k.KeyId) + return errors.WithMessagef(err, "failed to describe key, id=%s", *k.KeyId) } if aws.StringValue(ki.KeyMetadata.KeyState) == "PendingDeletion" { continue @@ -269,7 +269,7 @@ func (p *Provider) EnumKeys(slotID uint, prefix string, keyInfoFunc func(id, lab ki.KeyMetadata.CreationDate, ) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } } return nil @@ -281,7 +281,7 @@ func (p *Provider) DestroyKeyPairOnSlot(slotID uint, keyID string) error { KeyId: &keyID, }) if err != nil { - return errors.Annotatef(err, "failed to schedule key deletion: %s", keyID) + return errors.WithMessagef(err, "failed to schedule key deletion: %s", keyID) } logger.Noticef("id=%s, deletion_time=%v", keyID, aws.TimeValue(resp.DeletionDate).Format(time.RFC3339)) @@ -293,14 +293,14 @@ func (p *Provider) DestroyKeyPairOnSlot(slotID uint, keyID string) error { func (p *Provider) KeyInfo(slotID uint, keyID string, includePublic bool, keyInfoFunc func(id, label, typ, class, currentVersionID, pubKey string, creationTime *time.Time) error) error { resp, err := p.kmsClient.DescribeKey(&kms.DescribeKeyInput{KeyId: &keyID}) if err != nil { - return errors.Annotatef(err, "failed to describe key, id=%s", keyID) + return errors.WithMessagef(err, "failed to describe key, id=%s", keyID) } pubKey := "" if includePublic { pub, err := p.kmsClient.GetPublicKey(&kms.GetPublicKeyInput{KeyId: &keyID}) if err != nil { - return errors.Annotatef(err, "failed to get public key, id=%s", keyID) + return errors.WithMessagef(err, "failed to get public key, id=%s", keyID) } pubKey = base64.StdEncoding.EncodeToString(pub.PublicKey) } @@ -315,7 +315,7 @@ func (p *Provider) KeyInfo(slotID uint, keyID string, includePublic bool, keyInf nil, ) if err != nil { - return errors.Trace(err) + return errors.WithStack(err) } return nil @@ -326,7 +326,7 @@ func (p *Provider) KeyInfo(slotID uint, keyID string, includePublic bool, keyInf func (p *Provider) ExportKey(keyID string) (string, []byte, error) { resp, err := p.kmsClient.DescribeKey(&kms.DescribeKeyInput{KeyId: &keyID}) if err != nil { - return "", nil, errors.Annotatef(err, "failed to describe key, id=%s", keyID) + return "", nil, errors.WithMessagef(err, "failed to describe key, id=%s", keyID) } uri := fmt.Sprintf("pkcs11:manufacturer=%s;id=%s;serial=%s;type=private", @@ -352,7 +352,7 @@ func (p *Provider) Close() error { func KmsLoader(tc cryptoprov.TokenConfig) (cryptoprov.Provider, error) { p, err := Init(tc) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return p, nil } diff --git a/xpki/cryptoprov/awskmscrypto/signer.go b/xpki/cryptoprov/awskmscrypto/signer.go index 65d4f4c..1def38d 100644 --- a/xpki/cryptoprov/awskmscrypto/signer.go +++ b/xpki/cryptoprov/awskmscrypto/signer.go @@ -9,7 +9,7 @@ import ( "reflect" "github.com/aws/aws-sdk-go/service/kms" - "github.com/juju/errors" + "github.com/pkg/errors" ) // Supported signature types by AWS KMS @@ -73,7 +73,7 @@ func (s *Signer) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) (si sigAlgo, err := sigAlgo(s.pubKey, opts) if err != nil { - return nil, errors.Annotatef(err, "unable to determine signature algorithm") + return nil, errors.WithMessagef(err, "unable to determine signature algorithm") } req := &kms.SignInput{ @@ -84,7 +84,7 @@ func (s *Signer) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) (si } resp, err := s.kmsClient.Sign(req) if err != nil { - return nil, errors.Annotatef(err, "unable to sign") + return nil, errors.WithMessagef(err, "unable to sign") } return resp.Signature, nil } diff --git a/xpki/cryptoprov/config.go b/xpki/cryptoprov/config.go index 1e31bce..2fde574 100644 --- a/xpki/cryptoprov/config.go +++ b/xpki/cryptoprov/config.go @@ -8,7 +8,7 @@ import ( "strings" "github.com/go-phorce/dolly/fileutil/resolve" - "github.com/juju/errors" + "github.com/pkg/errors" ) // TokenConfig holds PKCS#11 configuration information. @@ -91,13 +91,13 @@ func (c *tokenConfig) Attributes() string { func LoadTokenConfig(filename string) (TokenConfig, error) { cfr, err := os.Open(filename) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } defer cfr.Close() tokenConfig := new(tokenConfig) err = json.NewDecoder(cfr).Decode(tokenConfig) if err != nil { - return nil, errors.Annotatef(err, "failed to decode file: %s", filename) + return nil, errors.WithMessagef(err, "failed to decode file: %s", filename) } pin := tokenConfig.Pin() @@ -122,7 +122,7 @@ func LoadTokenConfig(filename string) (TokenConfig, error) { pb, err := ioutil.ReadFile(pinfile) if err != nil { - return nil, errors.Annotatef(err, "unable to load PIN for configuration: %s", filename) + return nil, errors.WithMessagef(err, "unable to load PIN for configuration: %s", filename) } tokenConfig.Pwd = string(pb) } diff --git a/xpki/cryptoprov/config_test.go b/xpki/cryptoprov/config_test.go index a0a09dc..334bc6a 100644 --- a/xpki/cryptoprov/config_test.go +++ b/xpki/cryptoprov/config_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/go-phorce/dolly/xpki/cryptoprov" - "github.com/juju/errors" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/xpki/cryptoprov/gcm.go b/xpki/cryptoprov/gcm.go index 17a7d3c..ffcdb7b 100644 --- a/xpki/cryptoprov/gcm.go +++ b/xpki/cryptoprov/gcm.go @@ -5,19 +5,19 @@ import ( "crypto/cipher" "github.com/go-phorce/dolly/xpki/certutil" - "github.com/juju/errors" + "github.com/pkg/errors" ) // GcmEncrypt returns encrypted blob with GCM cipher func GcmEncrypt(plaintext []byte, key []byte) ([]byte, error) { c, err := aes.NewCipher(key) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } gcm, err := cipher.NewGCM(c) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } nonce := certutil.Random(gcm.NonceSize()) @@ -29,12 +29,12 @@ func GcmEncrypt(plaintext []byte, key []byte) ([]byte, error) { func GcmDecrypt(ciphertext []byte, key []byte) ([]byte, error) { c, err := aes.NewCipher(key) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } gcm, err := cipher.NewGCM(c) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } nonceSize := gcm.NonceSize() @@ -45,7 +45,7 @@ func GcmDecrypt(ciphertext []byte, key []byte) ([]byte, error) { nonce, ciphertext := ciphertext[:nonceSize], ciphertext[nonceSize:] plain, err := gcm.Open(nil, nonce, ciphertext, nil) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return plain, nil diff --git a/xpki/cryptoprov/inmemcrypto/provider.go b/xpki/cryptoprov/inmemcrypto/provider.go index 076f2d9..e2f19ee 100644 --- a/xpki/cryptoprov/inmemcrypto/provider.go +++ b/xpki/cryptoprov/inmemcrypto/provider.go @@ -13,7 +13,7 @@ import ( "github.com/go-phorce/dolly/algorithms/guid" "github.com/go-phorce/dolly/xlog" - "github.com/juju/errors" + "github.com/pkg/errors" ) var logger = xlog.NewPackageLogger("github.com/go-phorce/dolly/xpki", "inmemcrypto") @@ -163,7 +163,7 @@ func (p *Provider) Serial() string { func (p *Provider) GetKey(keyID string) (crypto.PrivateKey, error) { pvk, err := p.inMemProv.getKey(keyID) if err != nil { - return nil, errors.Annotatef(err, "key not found: %s", keyID) + return nil, errors.WithMessagef(err, "key not found: %s", keyID) } return pvk, nil } @@ -173,7 +173,7 @@ func (p *Provider) GenerateRSAKey(label string, bits int, purpose int) (crypto.P reader := rand.Reader key, err := p.rsaKeyGenerator.GenerateKey(reader, bits) if err != nil { - return nil, errors.Annotatef(err, "unable to generate key, bit size: %d", bits) + return nil, errors.WithMessagef(err, "unable to generate key, bit size: %d", bits) } if len(label) == 0 { @@ -197,7 +197,7 @@ func (p *Provider) GenerateECDSAKey(label string, curve elliptic.Curve) (crypto. reader := rand.Reader key, err := p.ecdsaKeyGenerator.GenerateKey(curve, reader) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } if len(label) == 0 { @@ -229,7 +229,7 @@ func (p *Provider) ExportKey(keyID string) (string, []byte, error) { prov, err := p.inMemProv.getKey(keyID) if err != nil { - return "", nil, errors.Annotatef(err, "unable to get key: %s", keyID) + return "", nil, errors.WithMessagef(err, "unable to get key: %s", keyID) } priv := prov.(*provImpl).pvk @@ -245,7 +245,7 @@ func (p *Provider) ExportKey(keyID string) (string, []byte, error) { case *ecdsa.PrivateKey: key, err = x509.MarshalECPrivateKey(priv) if err != nil { - return "", nil, errors.Annotatef(err, "export EC key: %s", keyID) + return "", nil, errors.WithMessagef(err, "export EC key: %s", keyID) } block := pem.Block{ Type: "EC PRIVATE KEY", diff --git a/xpki/cryptoprov/loader.go b/xpki/cryptoprov/loader.go index 62722e7..ad085cb 100644 --- a/xpki/cryptoprov/loader.go +++ b/xpki/cryptoprov/loader.go @@ -4,7 +4,7 @@ import ( "sync" "github.com/go-phorce/dolly/xpki/crypto11" - "github.com/juju/errors" + "github.com/pkg/errors" ) // ProviderLoader is interface for loading provider by manufacturer @@ -46,7 +46,7 @@ func Unregister(manufacturer string) (ProviderLoader, error) { func LoadProvider(configLocation string) (Provider, error) { tc, err := LoadTokenConfig(configLocation) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } manufacturer := tc.Manufacturer() @@ -57,7 +57,7 @@ func LoadProvider(configLocation string) (Provider, error) { prov, err := loader(tc) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return prov, nil @@ -67,26 +67,26 @@ func LoadProvider(configLocation string) (Provider, error) { func Load(defaultConfig string, providersConfigs []string) (*Crypto, error) { p, err := LoadProvider(defaultConfig) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } c, err := New(p, nil) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } err = c.Add(p) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } for _, configLocation := range providersConfigs { p, err := LoadProvider(configLocation) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } err = c.Add(p) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } } return c, nil @@ -96,7 +96,7 @@ func Load(defaultConfig string, providersConfigs []string) (*Crypto, error) { func Crypto11Loader(cfg TokenConfig) (Provider, error) { p, err := crypto11.Init(cfg) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return p, nil } diff --git a/xpki/cryptoprov/loader_test.go b/xpki/cryptoprov/loader_test.go index ec3c2e5..d89e607 100644 --- a/xpki/cryptoprov/loader_test.go +++ b/xpki/cryptoprov/loader_test.go @@ -6,7 +6,7 @@ import ( "github.com/go-phorce/dolly/xpki/cryptoprov" "github.com/go-phorce/dolly/xpki/cryptoprov/testprov" - "github.com/juju/errors" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -14,7 +14,7 @@ import ( func inmemloader(_ cryptoprov.TokenConfig) (cryptoprov.Provider, error) { p, err := testprov.Init() if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return p, nil } diff --git a/xpki/cryptoprov/provider.go b/xpki/cryptoprov/provider.go index 419e452..bb84a8a 100644 --- a/xpki/cryptoprov/provider.go +++ b/xpki/cryptoprov/provider.go @@ -6,7 +6,7 @@ import ( "time" "github.com/go-phorce/dolly/xlog" - "github.com/juju/errors" + "github.com/pkg/errors" ) var logger = xlog.NewPackageLogger("github.com/go-phorce/dolly/xpki", "cryptoprov") @@ -60,7 +60,7 @@ func New(defaultProvider Provider, providers []Provider) (*Crypto, error) { if providers != nil { for _, p := range providers { if err := c.Add(p); err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } } } @@ -91,7 +91,7 @@ func (c *Crypto) ByManufacturer(manufacturer string) (Provider, error) { p, ok := c.byManufacturer[manufacturer] if !ok { - return nil, errors.NotFoundf("provider for manufacturer %s", manufacturer) + return nil, errors.Errorf("provider for manufacturer %q not found", manufacturer) } return p, nil } diff --git a/xpki/cryptoprov/provider_test.go b/xpki/cryptoprov/provider_test.go index 231c3e6..964d1a1 100644 --- a/xpki/cryptoprov/provider_test.go +++ b/xpki/cryptoprov/provider_test.go @@ -51,7 +51,7 @@ func Test_P11(t *testing.T) { assert.NoError(t, err) _, err = cp.ByManufacturer("NetHSM") assert.Error(t, err) - assert.Equal(t, "provider for manufacturer NetHSM not found", err.Error()) + assert.Equal(t, "provider for manufacturer \"NetHSM\" not found", err.Error()) keyURI, keyBytes, err := d.ExportKey("test") assert.Error(t, err) diff --git a/xpki/cryptoprov/testprov/provider.go b/xpki/cryptoprov/testprov/provider.go index d13a60d..e53baef 100644 --- a/xpki/cryptoprov/testprov/provider.go +++ b/xpki/cryptoprov/testprov/provider.go @@ -11,7 +11,7 @@ import ( "strings" "github.com/go-phorce/dolly/algorithms/guid" - "github.com/juju/errors" + "github.com/pkg/errors" ) // inMemProv stores keyID to signer mapping in memory. Private keys are not exportable. @@ -154,7 +154,7 @@ func (p *Provider) Serial() string { func (p *Provider) GetKey(keyID string) (crypto.PrivateKey, error) { pvk, err := p.inMemProv.getKey(keyID) if err != nil { - return nil, errors.Annotatef(err, "GetKey(%s)", keyID) + return nil, errors.WithMessagef(err, "GetKey(%s)", keyID) } return pvk, nil } @@ -164,7 +164,7 @@ func (p *Provider) GenerateRSAKey(label string, bits int, purpose int) (crypto.P reader := rand.Reader key, err := p.rsaKeyGenerator.GenerateKey(reader, bits) if err != nil { - return nil, errors.Annotatef(err, "bitSize=%d", bits) + return nil, errors.WithMessagef(err, "bitSize=%d", bits) } if len(label) == 0 { @@ -188,7 +188,7 @@ func (p *Provider) GenerateECDSAKey(label string, curve elliptic.Curve) (crypto. reader := rand.Reader key, err := p.ecdsaKeyGenerator.GenerateKey(curve, reader) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } if len(label) == 0 { @@ -218,7 +218,7 @@ func (p *Provider) IdentifyKey(priv crypto.PrivateKey) (keyID, label string, err func (p *Provider) ExportKey(keyID string) (string, []byte, error) { s, err := p.inMemProv.getKey(keyID) if err != nil { - return "", nil, errors.Annotatef(err, "keyID=%s", keyID) + return "", nil, errors.WithMessagef(err, "keyID=%s", keyID) } si, ok := s.(*provImpl) diff --git a/xpki/cryptoprov/uri.go b/xpki/cryptoprov/uri.go index 1d497cf..95af8a7 100644 --- a/xpki/cryptoprov/uri.go +++ b/xpki/cryptoprov/uri.go @@ -5,7 +5,7 @@ import ( "net/url" "strings" - "github.com/juju/errors" + "github.com/pkg/errors" ) // PrivateKeyURI holds PKCS#11 private key information. @@ -68,17 +68,17 @@ func (k *keyURI) ID() string { func ParseTokenURI(uri string) (TokenConfig, error) { u, err := url.Parse(uri) if err != nil { - return nil, errors.Annotatef(err, "invalid URI: %s", uri) + return nil, errors.WithMessagef(err, "invalid URI: %s", uri) } if u.Scheme != "pkcs11" { - return nil, errors.Annotate(ErrInvalidURI, uri) + return nil, errors.WithMessage(ErrInvalidURI, uri) } c := new(tokenConfig) pk11PAttr, err := url.ParseQuery(strings.ReplaceAll(u.Opaque, ";", "&")) if err != nil { - return nil, errors.Annotatef(err, "invalid URI: %s", uri) + return nil, errors.WithMessagef(err, "invalid URI: %s", uri) } setIfPresent(pk11PAttr, "manufacturer", &c.Man) @@ -100,12 +100,12 @@ func ParseTokenURI(uri string) (TokenConfig, error) { pinURI.Path = pinURI.Opaque } if err != nil || pinURI.Scheme != "file" || pinURI.Path == "" { - return nil, errors.Annotate(ErrInvalidURI, uri) + return nil, errors.WithMessage(ErrInvalidURI, uri) } pin, err := ioutil.ReadFile(pinURI.Path) if err != nil { - return nil, errors.Annotate(ErrInvalidURI, uri) + return nil, errors.WithMessage(ErrInvalidURI, uri) } c.Pwd = strings.TrimSpace(string(pin)) @@ -119,17 +119,17 @@ func ParseTokenURI(uri string) (TokenConfig, error) { func ParsePrivateKeyURI(uri string) (PrivateKeyURI, error) { u, err := url.Parse(uri) if err != nil { - return nil, errors.Annotatef(err, "invalid URI: %s", uri) + return nil, errors.WithMessagef(err, "invalid URI: %s", uri) } if u.Scheme != "pkcs11" { - return nil, errors.Annotate(ErrInvalidURI, uri) + return nil, errors.WithMessage(ErrInvalidURI, uri) } c := new(keyURI) pk11PAttr, err := url.ParseQuery(strings.ReplaceAll(u.Opaque, ";", "&")) if err != nil { - return nil, errors.Annotatef(err, "invalid URI: %s", uri) + return nil, errors.WithMessagef(err, "invalid URI: %s", uri) } setIfPresent(pk11PAttr, "manufacturer", &c.manufacturer) @@ -140,7 +140,7 @@ func ParsePrivateKeyURI(uri string) (PrivateKeyURI, error) { var objtype string setIfPresent(pk11PAttr, "type", &objtype) if objtype != "private" || c.tokenSerial == "" || c.id == "" { - return nil, errors.Annotate(ErrInvalidPrivateKeyURI, uri) + return nil, errors.WithMessage(ErrInvalidPrivateKeyURI, uri) } c.manufacturer = strings.TrimSpace(strings.TrimRight(string(c.manufacturer), "\x00")) diff --git a/xpki/cryptoprov/utils.go b/xpki/cryptoprov/utils.go index 62b8aa6..a4625ab 100644 --- a/xpki/cryptoprov/utils.go +++ b/xpki/cryptoprov/utils.go @@ -13,7 +13,7 @@ import ( "github.com/cloudflare/cfssl/helpers" "github.com/go-phorce/dolly/xpki/gpg" - "github.com/juju/errors" + "github.com/pkg/errors" "golang.org/x/crypto/openpgp/packet" ) @@ -27,28 +27,28 @@ func (c *Crypto) LoadGPGPrivateKey(creationTime time.Time, key []byte) (*packet. if strings.HasPrefix(keyPem, "pkcs11") { pkuri, err := ParsePrivateKeyURI(keyPem) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } provider, err := c.ByManufacturer(pkuri.Manufacturer()) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } s, err := provider.GetKey(pkuri.ID()) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } pk, err = gpg.ConvertToPacketPrivateKey(creationTime, s) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } } else { pk, err = gpg.ConvertPemToPgpPrivateKey(creationTime, key) if err != nil { - return nil, errors.Annotatef(err, "convert PEM key to PGP format: %v", key) + return nil, errors.WithMessagef(err, "convert PEM key to PGP format: %v", key) } } return pk, nil @@ -65,22 +65,22 @@ func (c *Crypto) LoadPrivateKey(key []byte) (Provider, crypto.PrivateKey, error) if strings.HasPrefix(keyPem, "pkcs11") { pkuri, err := ParsePrivateKeyURI(keyPem) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } provider, err = c.ByManufacturer(pkuri.Manufacturer()) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } pvk, err = provider.GetKey(pkuri.ID()) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } } else { pvk, err = ParsePrivateKeyPEM(key) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } } @@ -184,12 +184,12 @@ func (c *Crypto) TLSKeyPair(certPEMBlock, keyPEMBlock []byte) (*tls.Certificate, // to check that it looks sane and matches the private key. cert.Leaf, err = x509.ParseCertificate(cert.Certificate[0]) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } _, cert.PrivateKey, err = c.LoadPrivateKey(keyPEMBlock) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return cert, nil diff --git a/xpki/csr/csr.go b/xpki/csr/csr.go index 784247c..1e8429b 100644 --- a/xpki/csr/csr.go +++ b/xpki/csr/csr.go @@ -12,7 +12,7 @@ import ( "strings" "time" - "github.com/juju/errors" + "github.com/pkg/errors" ) // Signer interface to sign CSR @@ -185,12 +185,12 @@ func appendIf(s string, a *[]string) { func Parse(csrBytes []byte) (*x509.Certificate, error) { csrv, err := x509.ParseCertificateRequest(csrBytes) if err != nil { - return nil, errors.Annotatef(err, "failed to parse") + return nil, errors.WithMessagef(err, "failed to parse") } err = csrv.CheckSignature() if err != nil { - return nil, errors.Annotatef(err, "key mismatch") + return nil, errors.WithMessagef(err, "key mismatch") } template := &x509.Certificate{ @@ -211,7 +211,7 @@ func Parse(csrBytes []byte) (*x509.Certificate, error) { var rest []byte if rest, err = asn1.Unmarshal(val.Value, &constraints); err != nil { - return nil, errors.Annotate(err, "failed to parse BasicConstraints") + return nil, errors.WithMessage(err, "failed to parse BasicConstraints") } else if len(rest) != 0 { return nil, errors.New("failed to parse BasicConstraints: trailing data") } diff --git a/xpki/csr/csrprov.go b/xpki/csr/csrprov.go index af85bbe..807cd03 100644 --- a/xpki/csr/csrprov.go +++ b/xpki/csr/csrprov.go @@ -15,7 +15,7 @@ import ( "github.com/go-phorce/dolly/xlog" "github.com/go-phorce/dolly/xpki/cryptoprov" - "github.com/juju/errors" + "github.com/pkg/errors" ) var logger = xlog.NewPackageLogger("github.com/go-phorce/dolly/xpki", "csr") @@ -53,7 +53,7 @@ func (c *Provider) NewSigningCertificateRequest( func (c *Provider) CreateRequestAndExportKey(req *CertificateRequest) (csrPEM, key []byte, keyID string, pub crypto.PublicKey, err error) { err = req.Validate() if err != nil { - err = errors.Annotate(err, "invalid request") + err = errors.WithMessage(err, "invalid request") return } @@ -62,21 +62,21 @@ func (c *Provider) CreateRequestAndExportKey(req *CertificateRequest) (csrPEM, k csrPEM, priv, keyID, err = c.GenerateKeyAndRequest(req) if err != nil { key = nil - err = errors.Annotate(err, "process request") + err = errors.WithMessage(err, "process request") return } s, ok := priv.(crypto.Signer) if !ok { key = nil - err = errors.Annotate(err, "unable to convert key to crypto.Signer") + err = errors.WithMessage(err, "unable to convert key to crypto.Signer") return } pub = s.Public() uri, keyBytes, err := c.provider.ExportKey(keyID) if err != nil { - err = errors.Annotate(err, "key URI") + err = errors.WithMessage(err, "key URI") return } @@ -102,14 +102,14 @@ func (c *Provider) GenerateKeyAndRequest(req *CertificateRequest) (csrPEM []byte priv, err = req.KeyRequest.Generate() if err != nil { - err = errors.Annotate(err, "generate key") + err = errors.WithMessage(err, "generate key") return } var label string keyID, label, err = c.provider.IdentifyKey(priv) if err != nil { - err = errors.Annotate(err, "identify key") + err = errors.WithMessage(err, "identify key") return } @@ -137,7 +137,7 @@ func (c *Provider) GenerateKeyAndRequest(req *CertificateRequest) (csrPEM []byte csrPEM, err = x509.CreateCertificateRequest(rand.Reader, &template, priv) if err != nil { - err = errors.Annotate(err, "create CSR") + err = errors.WithMessage(err, "create CSR") return } block := pem.Block{ diff --git a/xpki/csr/keyreq.go b/xpki/csr/keyreq.go index ec87b75..0895b0c 100644 --- a/xpki/csr/keyreq.go +++ b/xpki/csr/keyreq.go @@ -7,7 +7,7 @@ import ( "strings" "github.com/go-phorce/dolly/xpki/cryptoprov" - "github.com/juju/errors" + "github.com/pkg/errors" ) const ( @@ -85,17 +85,17 @@ func (kr *keyRequest) Generate() (crypto.PrivateKey, error) { case "RSA": err := validateRSAKeyPairInfoHandler(kr.Size()) if err != nil { - return nil, errors.Annotate(err, "validate RSA key") + return nil, errors.WithMessage(err, "validate RSA key") } pk, err := kr.prov.GenerateRSAKey(kr.Label(), kr.Size(), kr.Purpose()) if err != nil { - return nil, errors.Annotate(err, "generate RSA key") + return nil, errors.WithMessage(err, "generate RSA key") } return pk, nil case "ECDSA": err := validateECDSAKeyPairCurveInfoHandler(kr.Size()) if err != nil { - return nil, errors.Annotate(err, "validate ECDSA key") + return nil, errors.WithMessage(err, "validate ECDSA key") } var curve elliptic.Curve @@ -111,7 +111,7 @@ func (kr *keyRequest) Generate() (crypto.PrivateKey, error) { } pk, err := kr.prov.GenerateECDSAKey(kr.Label(), curve) if err != nil { - return nil, errors.Annotate(err, "generate ECDSA key") + return nil, errors.WithMessage(err, "generate ECDSA key") } return pk, nil default: diff --git a/xpki/csr/types.go b/xpki/csr/types.go index 2101401..d991690 100644 --- a/xpki/csr/types.go +++ b/xpki/csr/types.go @@ -10,7 +10,7 @@ import ( "strings" "time" - "github.com/juju/errors" + "github.com/pkg/errors" ) const ( @@ -127,7 +127,7 @@ func parseObjectIdentifier(oidString string) (oid asn1.ObjectIdentifier, err err for i, intString := range segments { oid[i], err = strconv.Atoi(intString) if err != nil { - err = errors.Annotatef(err, "invalid OID") + err = errors.WithMessagef(err, "invalid OID") return } } diff --git a/xpki/csrprov/cfssl.go b/xpki/csrprov/cfssl.go index 9e832e2..716baa9 100644 --- a/xpki/csrprov/cfssl.go +++ b/xpki/csrprov/cfssl.go @@ -15,7 +15,7 @@ import ( "github.com/cloudflare/cfssl/signer" "github.com/cloudflare/cfssl/signer/local" "github.com/go-phorce/dolly/xpki/cryptoprov" - "github.com/juju/errors" + "github.com/pkg/errors" ) // A CertificateRequest encapsulates the API interface to the @@ -151,14 +151,14 @@ func MakeCAPolicy(req *CertificateRequest) (*config.Signing, error) { policy.Default.ExpiryString = req.CA.Expiry policy.Default.Expiry, err = time.ParseDuration(req.CA.Expiry) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } } if req.CA.Backdate != "" { policy.Default.Backdate, err = time.ParseDuration(req.CA.Backdate) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } } @@ -175,19 +175,19 @@ func MakeCAPolicy(req *CertificateRequest) (*config.Signing, error) { func ParseCaFiles(caFile, caKeyFile string) (cakey []byte, parsedCa *x509.Certificate, err error) { ca, err := ioutil.ReadFile(caFile) if err != nil { - err = errors.Annotatef(err, "load ca file") + err = errors.WithMessagef(err, "load ca file") return } cakey, err = ioutil.ReadFile(caKeyFile) if err != nil { - err = errors.Annotatef(err, "load ca-key file") + err = errors.WithMessagef(err, "load ca-key file") return } parsedCa, err = helpers.ParseCertificatePEM(ca) if err != nil { - err = errors.Annotatef(err, "parse ca file") + err = errors.WithMessagef(err, "parse ca file") return } @@ -199,11 +199,11 @@ func ParseCaFiles(caFile, caKeyFile string) (cakey []byte, parsedCa *x509.Certif func NewLocalCASignerFromFile(c *cryptoprov.Crypto, caFile, caKeyFile string, policy *config.Signing) (*local.Signer, crypto.Signer, error) { ca, err := ioutil.ReadFile(caFile) if err != nil { - return nil, nil, errors.Annotatef(err, "load ca file") + return nil, nil, errors.WithMessagef(err, "load ca file") } cakey, err := ioutil.ReadFile(caKeyFile) if err != nil { - return nil, nil, errors.Annotatef(err, "load ca-key file") + return nil, nil, errors.WithMessagef(err, "load ca-key file") } return NewLocalCASignerFromPEM(c, ca, cakey, policy) @@ -218,7 +218,7 @@ func NewLocalCASignerFromPEM(c *cryptoprov.Crypto, ca, caKey []byte, policy *con _, pvk, err := c.LoadPrivateKey(caKey) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } sign, supported := pvk.(crypto.Signer) @@ -228,13 +228,13 @@ func NewLocalCASignerFromPEM(c *cryptoprov.Crypto, ca, caKey []byte, policy *con parsedCa, err := helpers.ParseCertificatePEM(ca) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } signPolicy := config.Signing(*policy) localSigner, err := local.NewSigner(sign, parsedCa, signer.DefaultSigAlgo(sign), &signPolicy) if err != nil { - return nil, nil, errors.Trace(err) + return nil, nil, errors.WithStack(err) } return localSigner, sign, nil diff --git a/xpki/csrprov/csr.go b/xpki/csrprov/csr.go index 21614cf..80e742d 100644 --- a/xpki/csrprov/csr.go +++ b/xpki/csrprov/csr.go @@ -10,7 +10,7 @@ import ( "github.com/cloudflare/cfssl/signer" "github.com/cloudflare/cfssl/signer/local" - "github.com/juju/errors" + "github.com/pkg/errors" ) // NewSigningCertificateRequest creates new request for signing certificate @@ -33,20 +33,20 @@ func (c *Provider) NewRoot(req *CertificateRequest) (cert, csrPEM, key []byte, e // RootCA fixup policy, err := MakeCAPolicy(req) if err != nil { - err = errors.Annotate(err, "ca policy failed") + err = errors.WithMessage(err, "ca policy failed") return } err = ValidateCSR(req) if err != nil { - err = errors.Annotate(err, "invalid request") + err = errors.WithMessage(err, "invalid request") return } csrPEM, gkey, keyID, err := c.ParseCsrRequest(req) if err != nil { key = nil - err = errors.Annotate(err, "process request") + err = errors.WithMessage(err, "process request") return } @@ -54,7 +54,7 @@ func (c *Provider) NewRoot(req *CertificateRequest) (cert, csrPEM, key []byte, e uri, keyBytes, err := c.provider.ExportKey(keyID) if err != nil { - err = errors.Annotate(err, "key URI") + err = errors.WithMessage(err, "key URI") return } @@ -66,7 +66,7 @@ func (c *Provider) NewRoot(req *CertificateRequest) (cert, csrPEM, key []byte, e s, err := local.NewSigner(signkey, nil, signer.DefaultSigAlgo(signkey), policy) if err != nil { - err = errors.Annotate(err, "create signer") + err = errors.WithMessage(err, "create signer") return } @@ -81,7 +81,7 @@ func (c *Provider) NewRoot(req *CertificateRequest) (cert, csrPEM, key []byte, e func (c *Provider) ProcessCsrRequest(req *CertificateRequest) (csrPEM, key []byte, keyID string, pub crypto.PublicKey, err error) { err = ValidateCSR(req) if err != nil { - err = errors.Annotate(err, "invalid request") + err = errors.WithMessage(err, "invalid request") return } @@ -90,21 +90,21 @@ func (c *Provider) ProcessCsrRequest(req *CertificateRequest) (csrPEM, key []byt csrPEM, priv, keyID, err = c.ParseCsrRequest(req) if err != nil { key = nil - err = errors.Annotate(err, "process request") + err = errors.WithMessage(err, "process request") return } s, ok := priv.(crypto.Signer) if !ok { key = nil - err = errors.Annotate(err, "unable to convert key to crypto.Signer") + err = errors.WithMessage(err, "unable to convert key to crypto.Signer") return } pub = s.Public() uri, keyBytes, err := c.provider.ExportKey(keyID) if err != nil { - err = errors.Annotate(err, "key URI") + err = errors.WithMessage(err, "key URI") return } @@ -133,14 +133,14 @@ func (c *Provider) ParseCsrRequest(req *CertificateRequest) (csr []byte, priv cr priv, err = req.KeyRequest.Generate() if err != nil { - err = errors.Annotate(err, "generate key") + err = errors.WithMessage(err, "generate key") return } var label string keyID, label, err = c.provider.IdentifyKey(priv) if err != nil { - err = errors.Annotate(err, "identify key") + err = errors.WithMessage(err, "identify key") return } @@ -163,8 +163,8 @@ func (c *Provider) ParseCsrRequest(req *CertificateRequest) (csr []byte, priv cr csr, err = x509.CreateCertificateRequest(rand.Reader, &tpl, priv) if err != nil { - logger.Errorf("failed to generate a CSR: %v", errors.Trace(err)) - err = errors.Annotate(err, "generate csr") + logger.Errorf("failed to generate a CSR: %v", errors.WithStack(err)) + err = errors.WithMessage(err, "generate csr") return } block := pem.Block{ diff --git a/xpki/csrprov/keyreq.go b/xpki/csrprov/keyreq.go index 2a94751..f579f5d 100644 --- a/xpki/csrprov/keyreq.go +++ b/xpki/csrprov/keyreq.go @@ -6,7 +6,7 @@ import ( "crypto/x509" "github.com/go-phorce/dolly/xpki/cryptoprov" - "github.com/juju/errors" + "github.com/pkg/errors" ) const ( @@ -84,17 +84,17 @@ func (kr *keyRequest) Generate() (crypto.PrivateKey, error) { case "rsa", "RSA": err := validateRSAKeyPairInfoHandler(kr.Size()) if err != nil { - return nil, errors.Annotate(err, "validate RSA key") + return nil, errors.WithMessage(err, "validate RSA key") } pk, err := kr.prov.GenerateRSAKey(kr.Label(), kr.Size(), kr.Purpose()) if err != nil { - return nil, errors.Annotate(err, "generate RSA key") + return nil, errors.WithMessage(err, "generate RSA key") } return pk, nil case "ecdsa", "ECDSA": err := validateECDSAKeyPairCurveInfoHandler(kr.Size()) if err != nil { - return nil, errors.Annotate(err, "validate ECDSA key") + return nil, errors.WithMessage(err, "validate ECDSA key") } var curve elliptic.Curve @@ -110,7 +110,7 @@ func (kr *keyRequest) Generate() (crypto.PrivateKey, error) { } pk, err := kr.prov.GenerateECDSAKey(kr.Label(), curve) if err != nil { - return nil, errors.Annotate(err, "generate ECDSA key") + return nil, errors.WithMessage(err, "generate ECDSA key") } return pk, nil default: diff --git a/xpki/gpg/keyring.go b/xpki/gpg/keyring.go index f754064..00a9d50 100644 --- a/xpki/gpg/keyring.go +++ b/xpki/gpg/keyring.go @@ -5,7 +5,7 @@ import ( "io/ioutil" "github.com/go-phorce/dolly/xpki/armor" - "github.com/juju/errors" + "github.com/pkg/errors" "golang.org/x/crypto/openpgp" ) @@ -25,7 +25,7 @@ func KeyRing(data []byte) (openpgp.EntityList, error) { // extract keys el, err := openpgp.ReadKeyRing(bytes.NewReader(block.Bytes)) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } // append keyring keyring = append(keyring, el...) @@ -44,12 +44,12 @@ func KeyRing(data []byte) (openpgp.EntityList, error) { func KeyRingFromFile(path string) (openpgp.EntityList, error) { data, err := ioutil.ReadFile(path) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } k, err := KeyRing(data) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return k, nil @@ -65,7 +65,7 @@ func KeyRingFromFiles(files []string) (openpgp.EntityList, error) { // read keyring in file el, err := KeyRingFromFile(path) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } // append keyring diff --git a/xpki/gpg/openpgp.go b/xpki/gpg/openpgp.go index d8f9589..9dfd4d1 100644 --- a/xpki/gpg/openpgp.go +++ b/xpki/gpg/openpgp.go @@ -16,7 +16,7 @@ import ( "time" "github.com/go-phorce/dolly/xlog" - "github.com/juju/errors" + "github.com/pkg/errors" "golang.org/x/crypto/openpgp" "golang.org/x/crypto/openpgp/armor" "golang.org/x/crypto/openpgp/packet" @@ -45,7 +45,7 @@ func ConvertTopX509CertificateToPGPPublicKey(certificateChainPem string) (*packe var x509Certificate *x509.Certificate x509Certificate, err := x509.ParseCertificate(block.Bytes) if err != nil { - return nil, errors.Annotate(err, "failed to parse certificate") + return nil, errors.WithMessage(err, "failed to parse certificate") } return Convert509CertificateToPGPPublicKey(x509Certificate), nil @@ -191,7 +191,7 @@ func CreateOpenPGPEntity(pubKey *packet.PublicKey, privKey *packet.PrivateKey, u if ops&OpenPGPEntitySignSelf == OpenPGPEntitySignSelf { err = selfSig.SignUserId(uid.Id, pubKey, privKey, &config) if err != nil { - return nil, errors.Annotate(err, "SignIdentity") + return nil, errors.WithMessage(err, "SignIdentity") } // selfIdentity.Signatures = append(selfIdentity.Signatures, selfSig) } @@ -199,7 +199,7 @@ func CreateOpenPGPEntity(pubKey *packet.PublicKey, privKey *packet.PrivateKey, u if ops&OpenPGPEntitySignIdentity == OpenPGPEntitySignIdentity { err = entity.SignIdentity(uid.Id, entity, &config) if err != nil { - return nil, errors.Annotate(err, "SignIdentity") + return nil, errors.WithMessage(err, "SignIdentity") } } */ @@ -207,7 +207,7 @@ func CreateOpenPGPEntity(pubKey *packet.PublicKey, privKey *packet.PrivateKey, u for _, subkey := range entity.Subkeys { err = subkey.Sig.SignKey(subkey.PublicKey, privKey, &config) if err != nil { - return nil, errors.Annotate(err, "SignIdentity") + return nil, errors.WithMessage(err, "SignIdentity") } // selfIdentity.Signatures = append(selfIdentity.Signatures, subkey.Sig) } @@ -250,7 +250,7 @@ func GetPgpPubkeyAlgo(pubkey *packet.PublicKey) (string, error) { func DecodeArmoredPgpSignature(armored io.Reader) (*packet.Signature, error) { block, err := armor.Decode(armored) if err != nil { - return nil, errors.Annotate(err, "decoding OpenPGP Armor") + return nil, errors.WithMessage(err, "decoding OpenPGP Armor") } if block.Type != openpgp.SignatureType { @@ -260,12 +260,12 @@ func DecodeArmoredPgpSignature(armored io.Reader) (*packet.Signature, error) { reader := packet.NewReader(block.Body) pkt, err := reader.Next() if err != nil { - return nil, errors.Annotate(err, "reading signature") + return nil, errors.WithMessage(err, "reading signature") } sig, ok := pkt.(*packet.Signature) if !ok { - return nil, errors.Annotate(err, "invalid signature") + return nil, errors.WithMessage(err, "invalid signature") } return sig, nil } @@ -308,14 +308,14 @@ func ConvertPemToPgpPrivateKey(creationTime time.Time, privateKeyPem []byte) (*p rsaPrivateKey, err := x509.ParsePKCS1PrivateKey(block.Bytes) if err != nil { - return nil, errors.Annotate(err, "failed to parse RSA private key") + return nil, errors.WithMessage(err, "failed to parse RSA private key") } pgpPrivateKey = packet.NewRSAPrivateKey(creationTime, rsaPrivateKey) case "EC PRIVATE KEY", "ECDSA PRIVATE KEY": ecPrivateKey, err := x509.ParseECPrivateKey(block.Bytes) if err != nil { - return nil, errors.Annotate(err, "failed to parse EC private key") + return nil, errors.WithMessage(err, "failed to parse EC private key") } pgpPrivateKey = packet.NewECDSAPrivateKey(creationTime, ecPrivateKey) @@ -330,7 +330,7 @@ func ConvertPemToPgpPrivateKey(creationTime time.Time, privateKeyPem []byte) (*p func VerifySignaturePGP(signed hash.Hash, pemSignature string, pubkey *packet.PublicKey) error { sig, err := DecodeArmoredPgpSignature(strings.NewReader(pemSignature)) if err != nil { - return errors.Annotate(err, "decode armored PGP signature") + return errors.WithMessage(err, "decode armored PGP signature") } if sig.PubKeyAlgo != pubkey.PubKeyAlgo { @@ -347,7 +347,7 @@ func VerifySignaturePGP(signed hash.Hash, pemSignature string, pubkey *packet.Pu err = pubkey.VerifySignature(signed, sig) if err != nil { - return errors.Annotate(err, "detached PGP signature") + return errors.WithMessage(err, "detached PGP signature") } return nil @@ -368,11 +368,11 @@ func EncodePGPEntityToPEM(e *openpgp.Entity) ([]byte, error) { b := bytes.NewBufferString(comments) w, err := armor.Encode(b, openpgp.PublicKeyType, make(map[string]string)) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } err = e.Serialize(w) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } w.Close() return b.Bytes(), nil @@ -383,13 +383,13 @@ func DecodePGPEntityFromPEM(r io.Reader) (*openpgp.Entity, error) { // decode PEM p, err := armor.Decode(r) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } packets := packet.NewReader(p.Body) e, err := openpgp.ReadEntity(packets) if err != nil { - return nil, errors.Trace(err) + return nil, errors.WithStack(err) } return e, nil diff --git a/xpki/oid/maphash.go b/xpki/oid/maphash.go index 5ff668e..ffe0dd0 100644 --- a/xpki/oid/maphash.go +++ b/xpki/oid/maphash.go @@ -7,7 +7,7 @@ import ( "crypto/rsa" "encoding/asn1" - "github.com/juju/errors" + "github.com/pkg/errors" ) // HashAlgorithmInfo provides OID info for Hash algorithms @@ -166,7 +166,7 @@ func HashAlgorithmByOID(oid string) (*HashAlgorithmInfo, error) { item := LookupByOID(oid) algo, ok := item.(HashAlgorithmInfo) if !ok { - return nil, errors.NotFoundf(algNotFoundFmt, oid) + return nil, errors.Errorf("algorithm not found: %s", oid) } return &algo, nil } @@ -210,7 +210,7 @@ func HashAlgorithmByName(name string) (*HashAlgorithmInfo, error) { item := LookupByName(name) algo, ok := item.(*HashAlgorithmInfo) if !ok { - return nil, errors.NotFoundf(algNotFoundFmt, name) + return nil, errors.Errorf("algorithm not found: %s", name) } return algo, nil } diff --git a/xpki/oid/mappubkey.go b/xpki/oid/mappubkey.go index db8ea6e..c81b58b 100644 --- a/xpki/oid/mappubkey.go +++ b/xpki/oid/mappubkey.go @@ -5,7 +5,7 @@ import ( "crypto/x509/pkix" "encoding/asn1" - "github.com/juju/errors" + "github.com/pkg/errors" ) // PublicKeyAlgorithmInfo provides OID info for Public Key algorithms @@ -83,7 +83,7 @@ func PublicKeyAlgorithmByOID(oid string) (*PublicKeyAlgorithmInfo, error) { item := LookupByOID(oid) algo, ok := item.(PublicKeyAlgorithmInfo) if !ok { - return nil, errors.NotFoundf(algNotFoundFmt, oid) + return nil, errors.Errorf("algorithm not found: %s", oid) } return &algo, nil } @@ -93,7 +93,7 @@ func PublicKeyAlgorithmByName(name string) (*PublicKeyAlgorithmInfo, error) { item := LookupByName(name) algo, ok := item.(*PublicKeyAlgorithmInfo) if !ok { - return nil, errors.NotFoundf(algNotFoundFmt, name) + return nil, errors.Errorf("algorithm not found: %s", name) } return algo, nil } diff --git a/xpki/oid/mapsig.go b/xpki/oid/mapsig.go index a9ec44a..57c5f30 100644 --- a/xpki/oid/mapsig.go +++ b/xpki/oid/mapsig.go @@ -7,7 +7,7 @@ import ( "crypto/x509" "encoding/asn1" - "github.com/juju/errors" + "github.com/pkg/errors" ) // SignatureAlgorithmInfo provides OID info for Signature algorithms @@ -193,26 +193,26 @@ func SignatureAlgorithmByOID(oid string) (*SignatureAlgorithmInfo, error) { item := LookupByOID(oid) algo, ok := item.(SignatureAlgorithmInfo) if !ok { - return nil, errors.NotFoundf(algNotFoundFmt, oid) + return nil, errors.Errorf("algorithm not found: %s", oid) } return &algo, nil } // SignatureAlgorithmByName returns an algorithm by name -func SignatureAlgorithmByName(name string) (SignatureAlgorithmInfo, error) { +func SignatureAlgorithmByName(name string) (*SignatureAlgorithmInfo, error) { item := LookupByName(name) algo, ok := item.(SignatureAlgorithmInfo) if !ok { - return SignatureAlgorithmInfo{}, errors.NotFoundf(algNotFoundFmt, name) + return nil, errors.Errorf("algorithm not found: %s", name) } - return algo, nil + return &algo, nil } // SignatureAlgorithmByKey returns an algorithm by key func SignatureAlgorithmByKey(pkey interface{}) (*PublicKeyAlgorithmInfo, error) { key, ok := pkey.(crypto.Signer) if !ok { - return nil, errors.NotSupportedf("crypto.Signer") + return nil, errors.Errorf("not supported: crypto.Signer") } pub := key.Public() @@ -223,14 +223,14 @@ func SignatureAlgorithmByKey(pkey interface{}) (*PublicKeyAlgorithmInfo, error) case *ecdsa.PublicKey: return &ECDSA, nil } - return nil, errors.NotSupportedf("crypto.Signer type %T", pub) + return nil, errors.Errorf("not supported crypto.Signer type %T", pub) } // SignatureAlgorithmByKeyAndHash returns an algorithm by key and Hash func SignatureAlgorithmByKeyAndHash(pkey interface{}, hash crypto.Hash) (*SignatureAlgorithmInfo, error) { key, ok := pkey.(crypto.Signer) if !ok { - return nil, errors.NotSupportedf("crypto.Signer") + return nil, errors.Errorf("not supported crypto.Signer") } pub := key.Public() @@ -247,7 +247,7 @@ func SignatureAlgorithmByKeyAndHash(pkey interface{}, hash crypto.Hash) (*Signat case crypto.SHA512: return &RSAWithSHA512, nil default: - return nil, errors.NotSupportedf("RSA") + return nil, errors.New("not supported RSA") } case *ecdsa.PublicKey: switch hash { @@ -260,10 +260,10 @@ func SignatureAlgorithmByKeyAndHash(pkey interface{}, hash crypto.Hash) (*Signat case crypto.SHA512: return &ECDSAWithSHA512, nil default: - return nil, errors.NotSupportedf("ECDSA") + return nil, errors.New("not supported ECDSA") } } - return nil, errors.NotSupportedf("crypto.Signer type %T", pub) + return nil, errors.Errorf("not supported crypto.Signer type %T", pub) } // SignatureAlgorithmByX509 returns an algorithm by X509 identifier diff --git a/xpki/oid/mapsig_test.go b/xpki/oid/mapsig_test.go index 389ad9f..44eb323 100644 --- a/xpki/oid/mapsig_test.go +++ b/xpki/oid/mapsig_test.go @@ -10,7 +10,6 @@ import ( "encoding/asn1" "testing" - "github.com/juju/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -44,11 +43,11 @@ func Test_SignatureAlgorithmInfo(t *testing.T) { func Test_SignatureAlgorithmByName(t *testing.T) { s, err := SignatureAlgorithmByName(RSAWithSHA1.Name()) require.NoError(t, err) - assert.Equal(t, s, RSAWithSHA1) + assert.Equal(t, RSAWithSHA1, *s) - s, err = SignatureAlgorithmByName("invalid") + _, err = SignatureAlgorithmByName("invalid") assert.Error(t, err) - assert.True(t, errors.IsNotFound(err)) + assert.Contains(t, err.Error(), "not found") } func Test_SignatureAlgorithmByKey(t *testing.T) { diff --git a/xpki/oid/oid.go b/xpki/oid/oid.go index 30feec0..8a68dc6 100644 --- a/xpki/oid/oid.go +++ b/xpki/oid/oid.go @@ -5,11 +5,9 @@ import ( "strconv" "strings" - "github.com/juju/errors" + "github.com/pkg/errors" ) -const algNotFoundFmt = "algorithm %s" - // AlgType specifies OID algorithm type type AlgType int