Skip to content

Commit 271d9df

Browse files
authored
Abolished github.com/pkg/errors (#420)
* remove github.com/pkg/errors * `go mod tidy` * fix losted err wrap
1 parent 07e1738 commit 271d9df

3 files changed

Lines changed: 17 additions & 19 deletions

File tree

bindparam.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ package runtime
1616
import (
1717
"encoding"
1818
"encoding/json"
19+
"errors"
1920
"fmt"
2021
"net/url"
2122
"reflect"
2223
"strings"
2324
"time"
2425

25-
"github.com/pkg/errors"
26-
2726
"github.com/deepmap/oapi-codegen/pkg/types"
2827
)
2928

deepobject.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ package runtime
22

33
import (
44
"encoding/json"
5+
"errors"
56
"fmt"
6-
"github.com/deepmap/oapi-codegen/pkg/types"
77
"net/url"
88
"reflect"
99
"sort"
1010
"strconv"
1111
"strings"
1212
"time"
1313

14-
"github.com/pkg/errors"
14+
"github.com/deepmap/oapi-codegen/pkg/types"
1515
)
1616

1717
func marshalDeepObject(in interface{}, path []string) ([]string, error) {
@@ -25,7 +25,7 @@ func marshalDeepObject(in interface{}, path []string) ([]string, error) {
2525
newPath := append(path, strconv.Itoa(i))
2626
fields, err := marshalDeepObject(iface, newPath)
2727
if err != nil {
28-
return nil, errors.Wrap(err, "error traversing array")
28+
return nil, fmt.Errorf("error traversing array: %w", err)
2929
}
3030
result = append(result, fields...)
3131
}
@@ -45,7 +45,7 @@ func marshalDeepObject(in interface{}, path []string) ([]string, error) {
4545
newPath := append(path, k)
4646
fields, err := marshalDeepObject(t[k], newPath)
4747
if err != nil {
48-
return nil, errors.Wrap(err, "error traversing map")
48+
return nil, fmt.Errorf("error traversing map: %w", err)
4949
}
5050
result = append(result, fields...)
5151
}
@@ -69,16 +69,16 @@ func MarshalDeepObject(i interface{}, paramName string) (string, error) {
6969
// but it's complicated, error-prone code.
7070
buf, err := json.Marshal(i)
7171
if err != nil {
72-
return "", errors.Wrap(err, "failed to marshal input to JSON")
72+
return "", fmt.Errorf("failed to marshal input to JSON: %w", err)
7373
}
7474
var i2 interface{}
7575
err = json.Unmarshal(buf, &i2)
7676
if err != nil {
77-
return "", errors.Wrap(err, "failed to unmarshal JSON")
77+
return "", fmt.Errorf("failed to unmarshal JSON: %w", err)
7878
}
7979
fields, err := marshalDeepObject(i2, nil)
8080
if err != nil {
81-
return "", errors.Wrap(err, "error traversing JSON structure")
81+
return "", fmt.Errorf("error traversing JSON structure: %w", err)
8282
}
8383

8484
// Prefix the param name to each subscripted field.
@@ -152,7 +152,7 @@ func UnmarshalDeepObject(dst interface{}, paramName string, params url.Values) e
152152
fieldPaths := makeFieldOrValue(paths, fieldValues)
153153
err := assignPathValues(dst, fieldPaths)
154154
if err != nil {
155-
return errors.Wrap(err, "error assigning value to destination")
155+
return fmt.Errorf("error assigning value to destination: %w", err)
156156
}
157157

158158
return nil
@@ -205,7 +205,7 @@ func assignPathValues(dst interface{}, pathValues fieldOrValue) error {
205205
dstSlice := reflect.MakeSlice(it, sliceLength, sliceLength)
206206
err := assignSlice(dstSlice, pathValues)
207207
if err != nil {
208-
return errors.Wrap(err, "error assigning slice")
208+
return fmt.Errorf("error assigning slice: %w", err)
209209
}
210210
iv.Set(dstSlice)
211211
return nil
@@ -225,7 +225,7 @@ func assignPathValues(dst interface{}, pathValues fieldOrValue) error {
225225
var err error
226226
date.Time, err = time.Parse(types.DateFormat, pathValues.value)
227227
if err != nil {
228-
return errors.Wrap(err, "invalid date format")
228+
return fmt.Errorf("invalid date format: %w", err)
229229
}
230230
dst := iv
231231
if it != reflect.TypeOf(types.Date{}) {
@@ -246,7 +246,7 @@ func assignPathValues(dst interface{}, pathValues fieldOrValue) error {
246246
if err != nil {
247247
return fmt.Errorf("error parsing tim as RFC3339 or 2006-01-02 time: %s", err)
248248
}
249-
return errors.Wrap(err, "invalid date format")
249+
return fmt.Errorf("invalid date format: %w", err)
250250
}
251251
dst := iv
252252
if it != reflect.TypeOf(time.Time{}) {
@@ -259,7 +259,7 @@ func assignPathValues(dst interface{}, pathValues fieldOrValue) error {
259259
}
260260
fieldMap, err := fieldIndicesByJsonTag(iv.Interface())
261261
if err != nil {
262-
return errors.Wrap(err, "failed enumerating fields")
262+
return fmt.Errorf("failed enumerating fields: %w", err)
263263
}
264264
for _, fieldName := range sortedFieldOrValueKeys(pathValues.fields) {
265265
fieldValue := pathValues.fields[fieldName]
@@ -270,7 +270,7 @@ func assignPathValues(dst interface{}, pathValues fieldOrValue) error {
270270
field := iv.Field(fieldIndex)
271271
err = assignPathValues(field.Addr().Interface(), fieldValue)
272272
if err != nil {
273-
return errors.Wrapf(err, "error assigning field [%s]", fieldName)
273+
return fmt.Errorf("error assigning field [%s]: %w", fieldName, err)
274274
}
275275
}
276276
return nil
@@ -340,7 +340,7 @@ func assignSlice(dst reflect.Value, pathValues fieldOrValue) error {
340340
dstElem := dst.Index(i).Addr()
341341
err := assignPathValues(dstElem.Interface(), fieldOrValue{value: values[i]})
342342
if err != nil {
343-
return errors.Wrap(err, "error binding array")
343+
return fmt.Errorf("error binding array: %w", err)
344344
}
345345
}
346346

styleparam.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package runtime
1515

1616
import (
17+
"errors"
1718
"fmt"
1819
"net/url"
1920
"reflect"
@@ -22,8 +23,6 @@ import (
2223
"strings"
2324
"time"
2425

25-
"github.com/pkg/errors"
26-
2726
"github.com/deepmap/oapi-codegen/pkg/types"
2827
)
2928

@@ -185,7 +184,7 @@ func styleStruct(style string, explode bool, paramName string, paramLocation Par
185184
if timeVal, ok := marshalDateTimeValue(value); ok {
186185
styledVal, err := stylePrimitive(style, explode, paramName, paramLocation, timeVal)
187186
if err != nil {
188-
return "", errors.Wrap(err, "failed to style time")
187+
return "", fmt.Errorf("failed to style time: %w", err)
189188
}
190189
return styledVal, nil
191190
}

0 commit comments

Comments
 (0)