Skip to content

Commit 1769405

Browse files
thaJeztahzeroshade
andauthored
chore: replace golang.org/x/xerrors for stdlib errors (#763)
relates to: - apache/arrow#5997 - apache/arrow#16992 The golang.org/x/xerrors module is a transitional module for what became go1.13 errors. Most of its functionality is now available in stdlib errors, with the exception of stdlib not providing a stack-trace (and some utility functions related to that). Looking at history to see if that functionality was essential for using this package, I found that the golang.org/x/errors module was introduced in [apache/arrow@7126fdb], to address [ARROW-7357]. > we should migrate away from `pkg/errors` to `golang.org/x/xerrors` to > ensure better error handling (and one that is Go-1.13 compatible). Based on the above, it looks like the intent was to provide compatibility with go1.13+ errors, which are now mainline, so stdlib errors should be preferred for this. [ARROW-7357]: https://issues.apache.org/jira/browse/ARROW-7357 [apache/arrow@7126fdb]: apache/arrow@7126fdb ### Rationale for this change ### What changes are included in this PR? ### Are these changes tested? ### Are there any user-facing changes? Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Co-authored-by: Matt Topol <zotthewizard@gmail.com>
1 parent 6f308c3 commit 1769405

37 files changed

Lines changed: 150 additions & 156 deletions

arrow/cdata/cdata.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ import (
5454
"github.com/apache/arrow-go/v18/arrow/array"
5555
"github.com/apache/arrow-go/v18/arrow/bitutil"
5656
"github.com/apache/arrow-go/v18/arrow/memory"
57-
"golang.org/x/xerrors"
5857
)
5958

6059
type (
@@ -224,22 +223,22 @@ func importSchema(schema *CArrowSchema) (ret arrow.Field, err error) {
224223
var precision, scale int
225224

226225
if len(propList) < 2 || len(propList) > 3 {
227-
return ret, xerrors.Errorf("invalid decimal spec '%s': wrong number of properties", f)
226+
return ret, fmt.Errorf("invalid decimal spec '%s': wrong number of properties", f)
228227
} else if len(propList) == 3 {
229228
bitwidth, err = strconv.Atoi(propList[2])
230229
if err != nil {
231-
return ret, xerrors.Errorf("could not parse decimal bitwidth in '%s': %s", f, err.Error())
230+
return ret, fmt.Errorf("could not parse decimal bitwidth in '%s': %w", f, err)
232231
}
233232
}
234233

235234
precision, err = strconv.Atoi(propList[0])
236235
if err != nil {
237-
return ret, xerrors.Errorf("could not parse decimal precision in '%s': %s", f, err.Error())
236+
return ret, fmt.Errorf("could not parse decimal precision in '%s': %w", f, err)
238237
}
239238

240239
scale, err = strconv.Atoi(propList[1])
241240
if err != nil {
242-
return ret, xerrors.Errorf("could not parse decimal scale in '%s': %s", f, err.Error())
241+
return ret, fmt.Errorf("could not parse decimal scale in '%s': %w", f, err)
243242
}
244243

245244
switch bitwidth {
@@ -252,7 +251,7 @@ func importSchema(schema *CArrowSchema) (ret arrow.Field, err error) {
252251
case 256:
253252
dt = &arrow.Decimal256Type{Precision: int32(precision), Scale: int32(scale)}
254253
default:
255-
return ret, xerrors.Errorf("unsupported decimal bitwidth, got '%s'", f)
254+
return ret, fmt.Errorf("unsupported decimal bitwidth, got '%s'", f)
256255
}
257256
}
258257

@@ -328,7 +327,7 @@ func importSchema(schema *CArrowSchema) (ret arrow.Field, err error) {
328327

329328
if dt == nil {
330329
// if we didn't find a type, then it's something we haven't implemented.
331-
err = xerrors.New("unimplemented type")
330+
err = errors.New("unimplemented type")
332331
} else {
333332
ret.Type = dt
334333
}
@@ -797,7 +796,7 @@ func (imp *cimporter) importFixedSizePrimitive() error {
797796
values, err = imp.importFixedSizeBuffer(1, bitutil.BytesForBits(int64(fw.BitWidth())))
798797
} else {
799798
if fw.BitWidth() != 1 {
800-
return xerrors.New("invalid bitwidth")
799+
return errors.New("invalid bitwidth")
801800
}
802801
values, err = imp.importBitsBuffer(1)
803802
}

arrow/cdata/interface.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ package cdata
2121

2222
import (
2323
"context"
24+
"errors"
2425
"unsafe"
2526

2627
"github.com/apache/arrow-go/v18/arrow"
2728
"github.com/apache/arrow-go/v18/arrow/array"
2829
"github.com/apache/arrow-go/v18/arrow/arrio"
2930
"github.com/apache/arrow-go/v18/arrow/memory"
30-
"golang.org/x/xerrors"
3131
)
3232

3333
// SchemaFromPtr is a simple helper function to cast a uintptr to a *CArrowSchema
@@ -151,7 +151,7 @@ func ImportCRecordBatch(arr *CArrowArray, sc *CArrowSchema) (arrow.RecordBatch,
151151
}
152152

153153
if field.Type.ID() != arrow.STRUCT {
154-
return nil, xerrors.New("recordbatch array import must be of struct type")
154+
return nil, errors.New("recordbatch array import must be of struct type")
155155
}
156156

157157
return ImportCRecordBatchWithSchema(arr, arrow.NewSchema(field.Type.(*arrow.StructType).Fields(), &field.Metadata))

arrow/compute/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package compute
2020

2121
import (
22+
"errors"
2223
"fmt"
2324
"io"
2425
"time"
@@ -30,7 +31,6 @@ import (
3031
"github.com/apache/arrow-go/v18/arrow/internal/debug"
3132
"github.com/apache/arrow-go/v18/arrow/memory"
3233
"github.com/apache/arrow-go/v18/internal/utils"
33-
"golang.org/x/xerrors"
3434
)
3535

3636
type bufferWriteSeeker struct {
@@ -84,7 +84,7 @@ func (b *bufferWriteSeeker) Seek(offset int64, whence int) (int64, error) {
8484
newpos = b.buf.Len() + offs
8585
}
8686
if newpos < 0 {
87-
return 0, xerrors.New("negative result pos")
87+
return 0, errors.New("negative result pos")
8888
}
8989
b.pos = newpos
9090
return int64(newpos), nil

arrow/datatype_fixedwidth.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
package arrow
1818

1919
import (
20-
"cmp"
20+
"cmp"
21+
"errors"
2122
"fmt"
2223
"strconv"
2324
"sync"
@@ -26,7 +27,6 @@ import (
2627
"github.com/apache/arrow-go/v18/arrow/decimal"
2728
"github.com/apache/arrow-go/v18/arrow/internal/debug"
2829
"github.com/apache/arrow-go/v18/internal/json"
29-
"golang.org/x/xerrors"
3030
)
3131

3232
type BooleanType struct{}
@@ -143,11 +143,11 @@ func TimestampFromStringInLocation(val string, unit TimeUnit, loc *time.Location
143143
// more than nanosecond precision is provided
144144
switch {
145145
case unit == Second && lenWithoutZone > 19:
146-
return 0, zoneFmt != "", xerrors.New("provided more than second precision for timestamp[s]")
146+
return 0, zoneFmt != "", errors.New("provided more than second precision for timestamp[s]")
147147
case unit == Millisecond && lenWithoutZone > 23:
148-
return 0, zoneFmt != "", xerrors.New("provided more than millisecond precision for timestamp[ms]")
148+
return 0, zoneFmt != "", errors.New("provided more than millisecond precision for timestamp[ms]")
149149
case unit == Microsecond && lenWithoutZone > 26:
150-
return 0, zoneFmt != "", xerrors.New("provided more than microsecond precision for timestamp[us]")
150+
return 0, zoneFmt != "", errors.New("provided more than microsecond precision for timestamp[us]")
151151
}
152152

153153
format += zoneFmt
@@ -220,14 +220,14 @@ func Time32FromString(val string, unit TimeUnit) (Time32, error) {
220220
switch unit {
221221
case Second:
222222
if len(val) > 8 {
223-
return 0, xerrors.New("cannot convert larger than second precision to time32s")
223+
return 0, errors.New("cannot convert larger than second precision to time32s")
224224
}
225225
case Millisecond:
226226
if len(val) > 12 {
227-
return 0, xerrors.New("cannot convert larger than millisecond precision to time32ms")
227+
return 0, errors.New("cannot convert larger than millisecond precision to time32ms")
228228
}
229229
case Microsecond, Nanosecond:
230-
return 0, xerrors.New("time32 can only be seconds or milliseconds")
230+
return 0, errors.New("time32 can only be seconds or milliseconds")
231231
}
232232

233233
var (
@@ -275,10 +275,10 @@ func Time64FromString(val string, unit TimeUnit) (Time64, error) {
275275
switch unit {
276276
case Microsecond:
277277
if len(val) > 15 {
278-
return 0, xerrors.New("cannot convert larger than microsecond precision to time64us")
278+
return 0, errors.New("cannot convert larger than microsecond precision to time64us")
279279
}
280280
case Second, Millisecond:
281-
return 0, xerrors.New("time64 should only be microseconds or nanoseconds")
281+
return 0, errors.New("time64 should only be microseconds or nanoseconds")
282282
}
283283

284284
var (

arrow/internal/flight_integration/scenario.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
"github.com/apache/arrow-go/v18/arrow/internal/arrjson"
4141
"github.com/apache/arrow-go/v18/arrow/ipc"
4242
"github.com/apache/arrow-go/v18/arrow/memory"
43-
"golang.org/x/xerrors"
4443
"google.golang.org/grpc"
4544
"google.golang.org/grpc/codes"
4645
"google.golang.org/grpc/status"
@@ -367,7 +366,7 @@ func CheckActionResults(ctx context.Context, client flight.Client, action *fligh
367366

368367
res, err := stream.Recv()
369368
if res != nil || err != io.EOF {
370-
return xerrors.New("action result stream had too many entries")
369+
return errors.New("action result stream had too many entries")
371370
}
372371
return nil
373372
}
@@ -501,7 +500,7 @@ func (m *middlewareScenarioTester) RunClient(addr string, opts ...grpc.DialOptio
501500
// this call is expected to fail
502501
_, err = client.GetFlightInfo(ctx, &flight.FlightDescriptor{Type: flight.DescriptorCMD})
503502
if err == nil {
504-
return xerrors.New("expected call to fail")
503+
return errors.New("expected call to fail")
505504
}
506505

507506
if tm.received != "expected value" {

arrow/scalar/nested.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/apache/arrow-go/v18/arrow/array"
2626
"github.com/apache/arrow-go/v18/arrow/internal/debug"
2727
"github.com/apache/arrow-go/v18/arrow/memory"
28-
"golang.org/x/xerrors"
2928
)
3029

3130
type ListScalar interface {
@@ -331,7 +330,7 @@ func NewStructScalar(val []Scalar, typ arrow.DataType) *Struct {
331330

332331
func NewStructScalarWithNames(val []Scalar, names []string) (*Struct, error) {
333332
if len(val) != len(names) {
334-
return nil, xerrors.New("mismatching number of field names and child scalars")
333+
return nil, errors.New("mismatching number of field names and child scalars")
335334
}
336335

337336
fields := make([]arrow.Field, len(names))

arrow/scalar/scalar.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package scalar
1818

1919
import (
2020
"encoding/binary"
21+
"errors"
2122
"fmt"
2223
"math"
2324
"math/big"
@@ -37,7 +38,6 @@ import (
3738
"github.com/apache/arrow-go/v18/arrow/float16"
3839
"github.com/apache/arrow-go/v18/arrow/internal/debug"
3940
"github.com/apache/arrow-go/v18/arrow/memory"
40-
"golang.org/x/xerrors"
4141
)
4242

4343
// Scalar represents a single value of a specific DataType as opposed to
@@ -97,7 +97,7 @@ func (s *scalar) IsValid() bool { return s.Valid }
9797

9898
func (s *scalar) Validate() error {
9999
if s.Type == nil {
100-
return xerrors.New("scalar lacks a type")
100+
return errors.New("scalar lacks a type")
101101
}
102102
return nil
103103
}
@@ -130,7 +130,7 @@ func (n *Null) Validate() (err error) {
130130
return
131131
}
132132
if n.Valid {
133-
err = xerrors.New("null scalar should have Valid = false")
133+
err = errors.New("null scalar should have Valid = false")
134134
}
135135
return
136136
}

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ require (
4747
golang.org/x/exp v0.0.0-20260112195511-716be5621a96
4848
golang.org/x/sync v0.20.0
4949
golang.org/x/sys v0.43.0
50-
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da
5150
gonum.org/v1/gonum v0.17.0
5251
google.golang.org/grpc v1.80.0
5352
google.golang.org/protobuf v1.36.11

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@ golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
242242
golang.org/x/tools v0.43.0 h1:12BdW9CeB3Z+J/I/wj34VMl8X+fEXBxVR90JeMX5E7s=
243243
golang.org/x/tools v0.43.0/go.mod h1:uHkMso649BX2cZK6+RpuIPXS3ho2hZo4FVwfoy1vIk0=
244244
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
245-
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da h1:noIWHXmPHxILtqtCOPIhSt0ABwskkZKjD3bXGnZGpNY=
246-
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
247245
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
248246
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
249247
google.golang.org/genproto/googleapis/rpc v0.0.0-20260120221211-b8f7ae30c516 h1:sNrWoksmOyF5bvJUcnmbeAmQi8baNhqg5IWaI3llQqU=

internal/types/extension_types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ package types
1919

2020
import (
2121
"encoding/binary"
22+
"errors"
2223
"fmt"
2324
"reflect"
2425

2526
"github.com/apache/arrow-go/v18/arrow"
2627
"github.com/apache/arrow-go/v18/arrow/array"
27-
"golang.org/x/xerrors"
2828
)
2929

3030
// Parametric1Array is a simple int32 array for use with the Parametric1Type
@@ -100,7 +100,7 @@ func (Parametric1Type) Deserialize(storage arrow.DataType, data string) (arrow.E
100100
}
101101

102102
if storage.ID() != arrow.INT32 {
103-
return nil, xerrors.New("parametric1type: must have int32 as underlying storage type")
103+
return nil, errors.New("parametric1type: must have int32 as underlying storage type")
104104
}
105105

106106
return &Parametric1Type{arrow.ExtensionBase{Storage: arrow.PrimitiveTypes.Int32}, int32(binary.LittleEndian.Uint32([]byte(data)))}, nil
@@ -155,7 +155,7 @@ func (Parametric2Type) Deserialize(storage arrow.DataType, data string) (arrow.E
155155
}
156156

157157
if storage.ID() != arrow.INT32 {
158-
return nil, xerrors.New("parametric1type: must have int32 as underlying storage type")
158+
return nil, errors.New("parametric1type: must have int32 as underlying storage type")
159159
}
160160

161161
return &Parametric2Type{arrow.ExtensionBase{Storage: arrow.PrimitiveTypes.Int32}, int32(binary.LittleEndian.Uint32([]byte(data)))}, nil
@@ -214,7 +214,7 @@ func (ExtStructType) Serialize() string { return "ext-struct-type-unique-code" }
214214
// returning the correct type if it matches "ext-struct-type-unique-code".
215215
func (ExtStructType) Deserialize(_ arrow.DataType, serialized string) (arrow.ExtensionType, error) {
216216
if string(serialized) != "ext-struct-type-unique-code" {
217-
return nil, xerrors.New("type identifier did not match")
217+
return nil, errors.New("type identifier did not match")
218218
}
219219
return NewExtStructType(), nil
220220
}

0 commit comments

Comments
 (0)