Skip to content

Commit 515964d

Browse files
authored
Use Go standard library errors package (#45)
Replace the deprecated and archived `github.com/pkg/errors` package with the Go standard library `errors` package and `%w` wrapping so it can be used with `errors.Is()`. * Bump minimum Go version to 1.19 to automatically include transitive dependencies in the Go modules files. Signed-off-by: SuperQ <superq@gmail.com>
1 parent b0b9070 commit 515964d

File tree

6 files changed

+16
-57
lines changed

6 files changed

+16
-57
lines changed

go.mod

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
module github.com/lestrrat-go/strftime
22

3-
go 1.13
3+
go 1.19
44

55
require (
66
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc
7-
github.com/pkg/errors v0.9.1
87
github.com/stretchr/testify v1.8.4
98
)
9+
10+
require (
11+
github.com/davecgh/go-spew v1.1.1 // indirect
12+
github.com/pmezard/go-difflib v1.0.0 // indirect
13+
gopkg.in/yaml.v3 v3.0.1 // indirect
14+
)

go.sum

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
1-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
21
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
32
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
43
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2ttpEmkA4aQ3j4u9dStX2t4M8UM6qqNsG8=
54
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is=
6-
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
7-
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
85
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
96
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
10-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
11-
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
12-
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
13-
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
14-
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
157
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
168
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
179
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1810
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
19-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2011
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
2112
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/errors/errors_fmt.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

internal/errors/errors_pkg.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

specifications.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package strftime
22

33
import (
4+
"errors"
45
"fmt"
56
"sync"
6-
7-
"github.com/lestrrat-go/strftime/internal/errors"
87
)
98

109
// because there is no such thing was a sync.RWLocker
@@ -124,7 +123,7 @@ func (ds *specificationSet) Lookup(b byte) (Appender, error) {
124123
}
125124
v, ok := ds.store[b]
126125
if !ok {
127-
return nil, errors.Errorf(`lookup failed: '%%%c' was not found in specification set`, b)
126+
return nil, fmt.Errorf(`lookup failed: '%%%c' was not found in specification set`, b)
128127
}
129128
return v, nil
130129
}

strftime.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package strftime
22

33
import (
4+
"errors"
5+
"fmt"
46
"io"
57
"strings"
68
"sync"
79
"time"
8-
9-
"github.com/lestrrat-go/strftime/internal/errors"
1010
)
1111

1212
type compileHandler interface {
@@ -62,7 +62,7 @@ func compile(handler compileHandler, p string, ds SpecificationSet) error {
6262

6363
specification, err := ds.Lookup(p[1])
6464
if err != nil {
65-
return errors.Wrap(err, `pattern compilation failed`)
65+
return fmt.Errorf("pattern compilation failed: %w", err)
6666
}
6767

6868
handler.handle(specification)
@@ -127,14 +127,14 @@ func Format(p string, t time.Time, options ...Option) (string, error) {
127127
// TODO: this may be premature optimization
128128
ds, err := getSpecificationSetFor(options...)
129129
if err != nil {
130-
return "", errors.Wrap(err, `failed to get specification set`)
130+
return "", fmt.Errorf("failed to get specification set: %w", err)
131131
}
132132
h := getFmtAppendExecutor()
133133
defer releasdeFmtAppendExecutor(h)
134134

135135
h.t = t
136136
if err := compile(h, p, ds); err != nil {
137-
return "", errors.Wrap(err, `failed to compile format`)
137+
return "", fmt.Errorf("failed to compile format: %w", err)
138138
}
139139

140140
return string(h.dst), nil
@@ -152,14 +152,14 @@ func New(p string, options ...Option) (*Strftime, error) {
152152
// TODO: this may be premature optimization
153153
ds, err := getSpecificationSetFor(options...)
154154
if err != nil {
155-
return nil, errors.Wrap(err, `failed to get specification set`)
155+
return nil, fmt.Errorf("failed to get specification set: %w", err)
156156
}
157157

158158
var h appenderListBuilder
159159
h.list = &combiningAppend{}
160160

161161
if err := compile(&h, p, ds); err != nil {
162-
return nil, errors.Wrap(err, `failed to compile format`)
162+
return nil, fmt.Errorf("failed to compile format: %w", err)
163163
}
164164

165165
return &Strftime{

0 commit comments

Comments
 (0)