From 29c87dc946018617493cd90f7b3012dc5496b026 Mon Sep 17 00:00:00 2001 From: Gene Armstrong Date: Thu, 3 Jul 2025 08:33:45 -0700 Subject: [PATCH 1/6] chore: add unprocessable content error --- errors.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/errors.go b/errors.go index 762f3c8..7d32cbf 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 { From 0ab00e37f41fb7ae08cbd78cdac79627bc0ec23a Mon Sep 17 00:00:00 2001 From: Gene Armstrong Date: Thu, 3 Jul 2025 08:42:14 -0700 Subject: [PATCH 2/6] chore: add test for unprocessable content error --- errors_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) 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) From 2f596685865333e4654acd982a24d76e1609e2c9 Mon Sep 17 00:00:00 2001 From: Gene Armstrong Date: Wed, 9 Jul 2025 07:41:18 -0700 Subject: [PATCH 3/6] bump min go version to 1.13 --- errors.go | 6 ++++++ exports_113.go | 12 ------------ 2 files changed, 6 insertions(+), 12 deletions(-) delete mode 100644 exports_113.go diff --git a/errors.go b/errors.go index 7d32cbf..6347249 100644 --- a/errors.go +++ b/errors.go @@ -6,6 +6,12 @@ import ( "github.com/pkg/errors" ) +var ( + Is = errors.Is + As = errors.As + Unwrap = errors.Unwrap +) + // ErrorCode holds the type of errors type ErrorCode string diff --git a/exports_113.go b/exports_113.go deleted file mode 100644 index fa14a8f..0000000 --- a/exports_113.go +++ /dev/null @@ -1,12 +0,0 @@ -//go:build go1.13 -// +build go1.13 - -package errors - -import "errors" - -var ( - Is = errors.Is - As = errors.As - Unwrap = errors.Unwrap -) From 720a618325f6539b80e5f6173e472d3e87dc1ca8 Mon Sep 17 00:00:00 2001 From: Gene Armstrong Date: Wed, 9 Jul 2025 07:43:36 -0700 Subject: [PATCH 4/6] remove go 1.12 from ci action --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e00ccf0..341ff1b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: - go-version: [1.12.x, 1.13.x, 1.20.x] + go-version: [1.13.x, 1.20.x] os: [ubuntu-latest, macos-latest, windows-latest] env: From c1c5cb799f20f5188ecda3f7c8644cbd1ac90211 Mon Sep 17 00:00:00 2001 From: Gene Armstrong Date: Wed, 9 Jul 2025 07:59:49 -0700 Subject: [PATCH 5/6] bumped ci action versions --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 341ff1b..08c509f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,10 +21,10 @@ jobs: 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}} From 33a68a707a232c2b35b461566e691bd128c5e58c Mon Sep 17 00:00:00 2001 From: Gene Armstrong Date: Wed, 9 Jul 2025 08:06:54 -0700 Subject: [PATCH 6/6] bump min go version to 1.20 --- .github/workflows/ci.yml | 2 +- errors.go | 14 ++++---------- exports.go | 10 ++++++++++ exports_120.go | 10 ---------- go.mod | 13 ++++++++++++- go.sum | 1 - 6 files changed, 27 insertions(+), 23 deletions(-) create mode 100644 exports.go delete mode 100644 exports_120.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 08c509f..fd3536f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: - go-version: [1.13.x, 1.20.x] + go-version: [1.20.x] os: [ubuntu-latest, macos-latest, windows-latest] env: diff --git a/errors.go b/errors.go index 6347249..7f15c36 100644 --- a/errors.go +++ b/errors.go @@ -6,12 +6,6 @@ import ( "github.com/pkg/errors" ) -var ( - Is = errors.Is - As = errors.As - Unwrap = errors.Unwrap -) - // ErrorCode holds the type of errors type ErrorCode string @@ -37,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...)} } @@ -47,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...)} } @@ -57,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...)), @@ -65,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/exports.go b/exports.go new file mode 100644 index 0000000..cd68999 --- /dev/null +++ b/exports.go @@ -0,0 +1,10 @@ +package errors + +import "errors" + +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=