Skip to content

Commit b09b032

Browse files
committed
ARROW-7357: [Go] migrate to x/xerrors
1 parent 3fb2f72 commit b09b032

18 files changed

Lines changed: 180 additions & 183 deletions

File tree

go/arrow/array/compare.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
"github.com/apache/arrow/go/arrow"
2323
"github.com/apache/arrow/go/arrow/float16"
24-
"github.com/pkg/errors"
24+
"golang.org/x/xerrors"
2525
)
2626

2727
// RecordEqual reports whether the two provided records are equal.
@@ -166,7 +166,7 @@ func ArrayEqual(left, right Interface) bool {
166166
return arrayEqualDuration(l, r)
167167

168168
default:
169-
panic(errors.Errorf("arrow/array: unknown array type %T", l))
169+
panic(xerrors.Errorf("arrow/array: unknown array type %T", l))
170170
}
171171
}
172172

@@ -355,7 +355,7 @@ func arrayApproxEqual(left, right Interface, opt equalOption) bool {
355355
return arrayEqualDuration(l, r)
356356

357357
default:
358-
panic(errors.Errorf("arrow/array: unknown array type %T", l))
358+
panic(xerrors.Errorf("arrow/array: unknown array type %T", l))
359359
}
360360

361361
return false

go/arrow/array/interval.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/apache/arrow/go/arrow/bitutil"
2626
"github.com/apache/arrow/go/arrow/internal/debug"
2727
"github.com/apache/arrow/go/arrow/memory"
28-
"github.com/pkg/errors"
28+
"golang.org/x/xerrors"
2929
)
3030

3131
func NewIntervalData(data *Data) Interface {
@@ -35,7 +35,7 @@ func NewIntervalData(data *Data) Interface {
3535
case *arrow.DayTimeIntervalType:
3636
return NewDayTimeIntervalData(data)
3737
default:
38-
panic(errors.Errorf("arrow/array: unknown interval data type %T", data.dtype))
38+
panic(xerrors.Errorf("arrow/array: unknown interval data type %T", data.dtype))
3939
}
4040
}
4141

go/arrow/csv/reader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"github.com/apache/arrow/go/arrow/array"
2929
"github.com/apache/arrow/go/arrow/internal/debug"
3030
"github.com/apache/arrow/go/arrow/memory"
31-
"github.com/pkg/errors"
31+
"golang.org/x/xerrors"
3232
)
3333

3434
// Reader wraps encoding/csv.Reader and creates array.Records from a schema.
@@ -105,7 +105,7 @@ func NewReader(r io.Reader, schema *arrow.Schema, opts ...Option) *Reader {
105105
func (r *Reader) readHeader() error {
106106
records, err := r.r.Read()
107107
if err != nil {
108-
return errors.Wrapf(err, "arrow/csv: could not read header from file")
108+
return xerrors.Errorf("arrow/csv: could not read header from file: %w", err)
109109
}
110110

111111
if len(records) != len(r.schema.Fields()) {

go/arrow/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ go 1.12
2121
require (
2222
github.com/davecgh/go-spew v1.1.0 // indirect
2323
github.com/google/flatbuffers v1.11.0
24-
github.com/pkg/errors v0.8.1
2524
github.com/pmezard/go-difflib v1.0.0 // indirect
2625
github.com/stretchr/testify v1.2.0
26+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
2727
)

go/arrow/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
22
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
33
github.com/google/flatbuffers v1.11.0 h1:O7CEyB8Cb3/DmtxODGtLHcEvpr81Jm5qLg/hsHnxA2A=
44
github.com/google/flatbuffers v1.11.0/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
5-
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
6-
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
75
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
86
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
97
github.com/stretchr/testify v1.2.0 h1:LThGCOvhuJic9Gyd1VBCkhyUXmO8vKaBFvBsJ2k03rg=
108
github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
9+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
10+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

go/arrow/internal/arrjson/arrjson.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"github.com/apache/arrow/go/arrow/array"
2929
"github.com/apache/arrow/go/arrow/float16"
3030
"github.com/apache/arrow/go/arrow/memory"
31-
"github.com/pkg/errors"
31+
"golang.org/x/xerrors"
3232
)
3333

3434
const (
@@ -152,7 +152,7 @@ func dtypeToJSON(dt arrow.DataType) dataType {
152152
ByteWidth: dt.ByteWidth,
153153
}
154154
}
155-
panic(errors.Errorf("unknown arrow.DataType %v", dt))
155+
panic(xerrors.Errorf("unknown arrow.DataType %v", dt))
156156
}
157157

158158
func dtypeFromJSON(dt dataType, children []Field) arrow.DataType {
@@ -261,7 +261,7 @@ func dtypeFromJSON(dt dataType, children []Field) arrow.DataType {
261261
return arrow.FixedWidthTypes.Duration_ns
262262
}
263263
}
264-
panic(errors.Errorf("unknown DataType %#v", dt))
264+
panic(xerrors.Errorf("unknown DataType %#v", dt))
265265
}
266266

267267
func schemaToJSON(schema *arrow.Schema) Schema {
@@ -541,7 +541,7 @@ func arrayFromJSON(mem memory.Allocator, dt arrow.DataType, arr Array) array.Int
541541
data := make([][]byte, len(strdata))
542542
for i, v := range strdata {
543543
if len(v) != 2*dt.ByteWidth {
544-
panic(errors.Errorf("arrjson: invalid hex-string length (got=%d, want=%d)", len(v), 2*dt.ByteWidth))
544+
panic(xerrors.Errorf("arrjson: invalid hex-string length (got=%d, want=%d)", len(v), 2*dt.ByteWidth))
545545
}
546546
vv, err := hex.DecodeString(v)
547547
if err != nil {
@@ -618,7 +618,7 @@ func arrayFromJSON(mem memory.Allocator, dt arrow.DataType, arr Array) array.Int
618618
return bldr.NewArray()
619619

620620
default:
621-
panic(errors.Errorf("unknown data type %v %T", dt, dt))
621+
panic(xerrors.Errorf("unknown data type %v %T", dt, dt))
622622
}
623623
panic("impossible")
624624
}
@@ -791,7 +791,7 @@ func arrayToJSON(field arrow.Field, arr array.Interface) Array {
791791
for i := range o.Data {
792792
v := []byte(strings.ToUpper(hex.EncodeToString(arr.Value(i))))
793793
if len(v) != 2*dt.ByteWidth {
794-
panic(errors.Errorf("arrjson: invalid hex-string length (got=%d, want=%d)", len(v), 2*dt.ByteWidth))
794+
panic(xerrors.Errorf("arrjson: invalid hex-string length (got=%d, want=%d)", len(v), 2*dt.ByteWidth))
795795
}
796796
o.Data[i] = string(v) // re-convert as string to prevent json.Marshal from base64-encoding it.
797797
}
@@ -859,7 +859,7 @@ func arrayToJSON(field arrow.Field, arr array.Interface) Array {
859859
}
860860

861861
default:
862-
panic(errors.Errorf("unknown array type %T", arr))
862+
panic(xerrors.Errorf("unknown array type %T", arr))
863863
}
864864
panic("impossible")
865865
}
@@ -1129,7 +1129,7 @@ func strFromJSON(vs []interface{}) []string {
11291129
case json.Number:
11301130
o[i] = v.String()
11311131
default:
1132-
panic(errors.Errorf("could not convert %v (%T) to a string", v, v))
1132+
panic(xerrors.Errorf("could not convert %v (%T) to a string", v, v))
11331133
}
11341134
}
11351135
return o
@@ -1153,10 +1153,10 @@ func bytesFromJSON(vs []interface{}) [][]byte {
11531153
case json.Number:
11541154
o[i], err = hex.DecodeString(v.String())
11551155
default:
1156-
panic(errors.Errorf("could not convert %v (%T) to a string", v, v))
1156+
panic(xerrors.Errorf("could not convert %v (%T) to a string", v, v))
11571157
}
11581158
if err != nil {
1159-
panic(errors.Errorf("could not decode %v: %v", v, err))
1159+
panic(xerrors.Errorf("could not decode %v: %v", v, err))
11601160
}
11611161
}
11621162
return o
@@ -1340,7 +1340,7 @@ func buildArray(bldr array.Builder, data array.Interface) {
13401340

13411341
switch bldr := bldr.(type) {
13421342
default:
1343-
panic(errors.Errorf("unknown builder %T", bldr))
1343+
panic(xerrors.Errorf("unknown builder %T", bldr))
13441344

13451345
case *array.BooleanBuilder:
13461346
data := data.(*array.Boolean)

go/arrow/ipc/cmd/arrow-cat/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import (
6464

6565
"github.com/apache/arrow/go/arrow/ipc"
6666
"github.com/apache/arrow/go/arrow/memory"
67-
"github.com/pkg/errors"
67+
"golang.org/x/xerrors"
6868
)
6969

7070
func main() {
@@ -90,7 +90,7 @@ func processStream(w io.Writer, rin io.Reader) error {
9090
for {
9191
r, err := ipc.NewReader(rin, ipc.WithAllocator(mem))
9292
if err != nil {
93-
if errors.Cause(err) == io.EOF {
93+
if xerrors.Is(err, io.EOF) {
9494
return nil
9595
}
9696
return err
@@ -131,7 +131,7 @@ func processFile(w io.Writer, fname string) error {
131131
hdr := make([]byte, len(ipc.Magic))
132132
_, err = io.ReadFull(f, hdr)
133133
if err != nil {
134-
return errors.Errorf("could not read file header: %v", err)
134+
return xerrors.Errorf("could not read file header: %w", err)
135135
}
136136
f.Seek(0, io.SeekStart)
137137

@@ -144,7 +144,7 @@ func processFile(w io.Writer, fname string) error {
144144

145145
r, err := ipc.NewFileReader(f, ipc.WithAllocator(mem))
146146
if err != nil {
147-
if errors.Cause(err) == io.EOF {
147+
if xerrors.Is(err, io.EOF) {
148148
return nil
149149
}
150150
return err

go/arrow/ipc/cmd/arrow-file-to-stream/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/apache/arrow/go/arrow/arrio"
2626
"github.com/apache/arrow/go/arrow/ipc"
2727
"github.com/apache/arrow/go/arrow/memory"
28-
"github.com/pkg/errors"
28+
"golang.org/x/xerrors"
2929
)
3030

3131
func main() {
@@ -56,7 +56,7 @@ func processFile(w io.Writer, fname string) error {
5656

5757
rr, err := ipc.NewFileReader(r, ipc.WithAllocator(mem))
5858
if err != nil {
59-
if errors.Cause(err) == io.EOF {
59+
if xerrors.Is(err, io.EOF) {
6060
return nil
6161
}
6262
return err
@@ -68,15 +68,15 @@ func processFile(w io.Writer, fname string) error {
6868

6969
n, err := arrio.Copy(ww, rr)
7070
if err != nil {
71-
return errors.Wrap(err, "could not copy ARROW stream")
71+
return xerrors.Errorf("could not copy ARROW stream: %w", err)
7272
}
7373
if got, want := n, int64(rr.NumRecords()); got != want {
74-
return errors.Errorf("invalid number of records written (got=%d, want=%d)", got, want)
74+
return xerrors.Errorf("invalid number of records written (got=%d, want=%d)", got, want)
7575
}
7676

7777
err = ww.Close()
7878
if err != nil {
79-
return errors.Wrap(err, "could not close output ARROW stream")
79+
return xerrors.Errorf("could not close output ARROW stream: %w", err)
8080
}
8181

8282
return nil

0 commit comments

Comments
 (0)