Skip to content

Commit

Permalink
First phase of eradicating github.com/pkg/errors (#32)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
lestrrat and mroth authored Apr 20, 2022
1 parent bd1e7b3 commit 7d018d1
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 9 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
18 changes: 18 additions & 0 deletions internal/errors/errors_fmt.go
Original file line number Diff line number Diff line change
@@ -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)
}
18 changes: 18 additions & 0 deletions internal/errors/errors_pkg.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion specifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion strftime.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sync"
"time"

"github.com/pkg/errors"
"github.com/lestrrat-go/strftime/internal/errors"
)

type compileHandler interface {
Expand Down

0 comments on commit 7d018d1

Please sign in to comment.