From 7d018d1f12d28d349bdc5c9515d5cd8f6ad666cf Mon Sep 17 00:00:00 2001 From: lestrrat <49281+lestrrat@users.noreply.github.com> Date: Wed, 20 Apr 2022 15:19:02 +0900 Subject: [PATCH] First phase of eradicating github.com/pkg/errors (#32) * build(deps): replace deprecated github.com/pkg/errors with stdlib replaces github.com/pkg/errors, which is now marked as archived and not maintained on github, with native >=go1.13 standard library functions. This preserves the error wrapping previously handled via errors.Wrap via the new %w directive in fmt.Errorf. * Remove 1.12 * implement errors as internal package * Add +build build constraints * tweak test name * quote * Update Changes * Update Changes * fix specifications.go Co-authored-by: Matthew Rothenberg --- .github/workflows/ci.yml | 7 ++++--- Changes | 14 ++++++++++++++ Makefile | 4 ++++ go.mod | 4 ++-- go.sum | 4 ++-- internal/errors/errors_fmt.go | 18 ++++++++++++++++++ internal/errors/errors_pkg.go | 18 ++++++++++++++++++ specifications.go | 2 +- strftime.go | 2 +- 9 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 internal/errors/errors_fmt.go create mode 100644 internal/errors/errors_pkg.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 39b6c3e..e61ffbe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,9 +6,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: [ '1.18', '1.17', '1.16', '1.15', '1.14', '1.13', '1.12' ] + go: [ '1.18', '1.17', '1.16', '1.15', '1.14', '1.13' ] + tags: [ 'strftime_native_errors', '' ] fail-fast: false - name: Go ${{ matrix.go }} test + name: "Go ${{ matrix.go }} test (tags: ${{ matrix.tags }})" steps: - name: Checkout repository uses: actions/checkout@v2 @@ -17,7 +18,7 @@ jobs: with: go-version: ${{ matrix.go }} - name: Test with coverage - run: make cover + run: make STRFTIME_TAGS=${{ matrix.tags }} cover - name: Upload code coverage to codecov if: matrix.go == '1.18' uses: codecov/codecov-action@v1 diff --git a/Changes b/Changes index 86218dd..b609b9b 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,20 @@ Changes ======= +v1.0.6 - UNRELEASED +[Miscellaneous] + * Minimum go version is now go 1.13 + * github.com/pkg/errors is going to be phased out in steps. In this release, + users may opt-in to using native errors using `fmt.Errorf("%w")` by + specifying the tag `strftime_native_errors`. In the next release, the default + will be to use native errors, but users will be able to opt-in to using + github.com/pkg/errors using a tag. The version after will remove github.com/pkg/errors. + + This is something that we normally would do over a major version upgrade + but since we do not expect this library to receive API breaking changes in the + near future and thus no v2 is expected, we have decided to do this over few + non-major releases. + v1.0.5 [New features] * `(strftime.Strftime).FormatBuffer([]byte, time.Time) []byte` has been added. diff --git a/Makefile b/Makefile index 7e9694d..b382171 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,11 @@ test: go test -v -race ./... cover: +ifeq ($(strip $(STRFTIME_TAGS)),) go test -v -race -coverpkg=./... -coverprofile=coverage.out ./... +else + go test -v -tags $(STRFTIME_TAGS) -race -coverpkg=./... -coverprofile=coverage.out ./... +endif viewcover: go tool cover -html=coverage.out diff --git a/go.mod b/go.mod index d74b99a..14a8c57 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,9 @@ module github.com/lestrrat-go/strftime -go 1.12 +go 1.13 require ( github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc - github.com/pkg/errors v0.8.1 + github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.3.0 ) diff --git a/go.sum b/go.sum index fa5ca75..db1aa50 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2ttpEmkA4aQ3j4u9dStX2t4M8UM6qqNsG8= github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= -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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/internal/errors/errors_fmt.go b/internal/errors/errors_fmt.go new file mode 100644 index 0000000..18871c1 --- /dev/null +++ b/internal/errors/errors_fmt.go @@ -0,0 +1,18 @@ +//go:build strftime_native_errors +// +build strftime_native_errors + +package errors + +import "fmt" + +func New(s string) error { + return fmt.Errorf(s) +} + +func Errorf(s string, args ...interface{}) error { + return fmt.Errorf(s, args...) +} + +func Wrap(err error, s string) error { + return fmt.Errorf(s+`: %w`, err) +} diff --git a/internal/errors/errors_pkg.go b/internal/errors/errors_pkg.go new file mode 100644 index 0000000..3579787 --- /dev/null +++ b/internal/errors/errors_pkg.go @@ -0,0 +1,18 @@ +//go:build !strftime_native_errors +// +build !strftime_native_errors + +package errors + +import "github.com/pkg/errors" + +func New(s string) error { + return errors.New(s) +} + +func Errorf(s string, args ...interface{}) error { + return errors.Errorf(s, args...) +} + +func Wrap(err error, s string) error { + return errors.Wrap(err, s) +} diff --git a/specifications.go b/specifications.go index b53ebc1..2b6e11f 100644 --- a/specifications.go +++ b/specifications.go @@ -4,7 +4,7 @@ import ( "fmt" "sync" - "github.com/pkg/errors" + "github.com/lestrrat-go/strftime/internal/errors" ) // because there is no such thing was a sync.RWLocker diff --git a/strftime.go b/strftime.go index f5e9fba..c869491 100644 --- a/strftime.go +++ b/strftime.go @@ -6,7 +6,7 @@ import ( "sync" "time" - "github.com/pkg/errors" + "github.com/lestrrat-go/strftime/internal/errors" ) type compileHandler interface {