diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e00ccf0..fd3536f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,17 +14,17 @@ jobs: strategy: matrix: - go-version: [1.12.x, 1.13.x, 1.20.x] + go-version: [1.20.x] os: [ubuntu-latest, macos-latest, windows-latest] env: ENV: test steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Install Go - uses: actions/setup-go@v1 + uses: actions/setup-go@v5 with: go-version: ${{matrix.go-version}} diff --git a/errors.go b/errors.go index 762f3c8..7f15c36 100644 --- a/errors.go +++ b/errors.go @@ -10,12 +10,13 @@ import ( type ErrorCode string const ( - InternalError ErrorCode = "Internal Error" - NotFound ErrorCode = "Not Found" - InvalidArgument ErrorCode = "Invalid Argument" - Unauthenticated ErrorCode = "Unauthenticated" - PermissionDenied ErrorCode = "Permission Denied" - Unknown ErrorCode = "Unknown" + InternalError ErrorCode = "Internal Error" + NotFound ErrorCode = "Not Found" + InvalidArgument ErrorCode = "Invalid Argument" + Unauthenticated ErrorCode = "Unauthenticated" + PermissionDenied ErrorCode = "Permission Denied" + UnprocessableContent ErrorCode = "Unprocessable Content" + Unknown ErrorCode = "Unknown" ) type customError struct { @@ -30,7 +31,7 @@ func (code ErrorCode) New(msg string) error { } // Newf creates a new customError with formatted message -func (code ErrorCode) Newf(msg string, args ...interface{}) error { +func (code ErrorCode) Newf(msg string, args ...any) error { return customError{code: code, originalError: fmt.Errorf(msg, args...)} } @@ -40,7 +41,7 @@ func (code ErrorCode) Wrap(err error, msg string) error { } // Wrapf creates a new wrapped error with formatted message -func (code ErrorCode) Wrapf(err error, msg string, args ...interface{}) error { +func (code ErrorCode) Wrapf(err error, msg string, args ...any) error { return customError{code: code, originalError: errors.Wrapf(err, msg, args...)} } @@ -50,7 +51,7 @@ func New(msg string) error { } // Newf creates an InternalError error with formatted message -func Newf(msg string, args ...interface{}) error { +func Newf(msg string, args ...any) error { return customError{ code: InternalError, originalError: errors.New(fmt.Sprintf(msg, args...)), @@ -58,7 +59,7 @@ func Newf(msg string, args ...interface{}) error { } // Wrapf an error with format string -func Wrapf(err error, msg string, args ...interface{}) error { +func Wrapf(err error, msg string, args ...any) error { wrappedError := errors.Wrapf(err, msg, args...) var customErr customError diff --git a/errors_test.go b/errors_test.go index b49cd8e..207c8d3 100644 --- a/errors_test.go +++ b/errors_test.go @@ -72,6 +72,16 @@ var _ = Describe("Errors", func() { Expect(fmt.Sprintf("%+v", errors.StackTrace(err))).To(ContainSubstring("/errors_test.go:")) }) + It("create an unprocessable content error", func() { + msg := "an error with a message" + err := errors.UnprocessableContent.New(msg) + + Expect(errors.Code(err)).To(Equal(errors.UnprocessableContent)) + Expect(err.Error()).To(Equal(msg)) + Expect(errors.DisplayMessage(err)).To(Equal("Unprocessable Content")) + Expect(fmt.Sprintf("%+v", errors.StackTrace(err))).To(ContainSubstring("/errors_test.go:")) + }) + It("creates an Unknown error", func() { msg := "an error with a message" err := errors.Unknown.New(msg) diff --git a/exports_113.go b/exports.go similarity index 74% rename from exports_113.go rename to exports.go index fa14a8f..cd68999 100644 --- a/exports_113.go +++ b/exports.go @@ -1,6 +1,3 @@ -//go:build go1.13 -// +build go1.13 - package errors import "errors" @@ -9,4 +6,5 @@ var ( Is = errors.Is As = errors.As Unwrap = errors.Unwrap + Join = errors.Join ) diff --git a/exports_120.go b/exports_120.go deleted file mode 100644 index 41e7a71..0000000 --- a/exports_120.go +++ /dev/null @@ -1,10 +0,0 @@ -//go:build go1.20 -// +build go1.20 - -package errors - -import "errors" - -var ( - Join = errors.Join -) diff --git a/go.mod b/go.mod index 1186b83..3fd7b21 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,20 @@ module github.com/neighborly/go-errors -go 1.13 +go 1.20 require ( github.com/onsi/ginkgo v1.11.0 github.com/onsi/gomega v1.8.1 github.com/pkg/errors v0.9.1 ) + +require ( + github.com/hpcloud/tail v1.0.0 // indirect + golang.org/x/net v0.0.0-20180906233101-161cd47e91fd // indirect + golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e // indirect + golang.org/x/text v0.3.0 // indirect + golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 // indirect + gopkg.in/fsnotify.v1 v1.4.7 // indirect + gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect + gopkg.in/yaml.v2 v2.2.4 // indirect +) diff --git a/go.sum b/go.sum index ecea431..d2beed9 100644 --- a/go.sum +++ b/go.sum @@ -13,7 +13,6 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=