From 80189603415486f38684633ef3d8dd9a5fbd7c81 Mon Sep 17 00:00:00 2001 From: jupblb Date: Thu, 26 Feb 2026 11:24:16 +0100 Subject: [PATCH 1/4] bindings/go/scip: replace cockroachdb/errors with stdlib errors/fmt Remove the github.com/cockroachdb/errors dependency and replace all usages with standard library equivalents: - errors.New (stdlib) - fmt.Errorf with %w for wrapping - errors.Join for combining errors This also removes ~6 transitive dependencies (cockroachdb/logtags, cockroachdb/redact, getsentry/sentry-go, gogo/protobuf, pkg/errors). Fixes a pre-existing bug in readVarint where errors.Newf was missing the loop index argument for the %d format verb. --- bindings/go/scip/go.mod | 10 ------ bindings/go/scip/go.sum | 50 ----------------------------- bindings/go/scip/parse.go | 29 +++++++++-------- bindings/go/scip/symbol_parser.go | 5 ++- bindings/go/scip/testutil/format.go | 10 +++--- 5 files changed, 22 insertions(+), 82 deletions(-) diff --git a/bindings/go/scip/go.mod b/bindings/go/scip/go.mod index b20b949e..64488ca3 100644 --- a/bindings/go/scip/go.mod +++ b/bindings/go/scip/go.mod @@ -3,7 +3,6 @@ module github.com/sourcegraph/scip/bindings/go/scip go 1.25.0 require ( - github.com/cockroachdb/errors v1.12.0 github.com/fatih/color v1.18.0 github.com/hexops/gotextdiff v1.0.3 github.com/sourcegraph/beaut v0.0.0-20240611013027-627e4c25335a @@ -20,24 +19,15 @@ require ( ) require ( - github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect - github.com/cockroachdb/redact v1.1.5 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/getsentry/sentry-go v0.27.0 // indirect - github.com/gogo/protobuf v1.3.2 // indirect github.com/hexops/valast v1.5.0 // indirect - github.com/kr/pretty v0.3.1 // indirect - github.com/kr/text v0.2.0 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/nightlyone/lockfile v1.0.0 // indirect - github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/rogpeppe/go-internal v1.14.1 // indirect golang.org/x/mod v0.33.0 // indirect golang.org/x/sync v0.19.0 // indirect golang.org/x/sys v0.41.0 // indirect - golang.org/x/text v0.34.0 // indirect golang.org/x/tools v0.42.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect mvdan.cc/gofumpt v0.9.2 // indirect diff --git a/bindings/go/scip/go.sum b/bindings/go/scip/go.sum index 1421c071..27f51736 100644 --- a/bindings/go/scip/go.sum +++ b/bindings/go/scip/go.sum @@ -1,22 +1,9 @@ -github.com/cockroachdb/errors v1.12.0 h1:d7oCs6vuIMUQRVbi6jWWWEJZahLCfJpnJSVobd1/sUo= -github.com/cockroachdb/errors v1.12.0/go.mod h1:SvzfYNNBshAVbZ8wzNc/UPK3w1vf0dKDUP41ucAIf7g= -github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= -github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= -github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= -github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= -github.com/getsentry/sentry-go v0.27.0 h1:Pv98CIbtB3LkMWmXi4Joa5OOcwbmnX88sF5qbK3r3Ps= -github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= -github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= -github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI= github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow= -github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= -github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= @@ -29,8 +16,6 @@ github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUq github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= github.com/hexops/valast v1.5.0 h1:FBTuvVi0wjTngtXJRZXMbkN/Dn6DgsUsBwch2DUJU8Y= github.com/hexops/valast v1.5.0/go.mod h1:Jcy1pNH7LNraVaAZDLyv21hHg2WBv9Nf9FL6fGxU7o4= -github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -41,60 +26,25 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/nightlyone/lockfile v1.0.0 h1:RHep2cFKK4PonZJDdEl4GmkabuhbsRMgk/k3uAmxBiA= github.com/nightlyone/lockfile v1.0.0/go.mod h1:rywoIealpdNse2r832aiD9jRk8ErCatROs6LzC841CI= -github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= -github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= -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/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/sourcegraph/beaut v0.0.0-20240611013027-627e4c25335a h1:j/CQ27s679M9wRGBRJYyXGrfkYuQA6VMnD7R08mHD9c= github.com/sourcegraph/beaut v0.0.0-20240611013027-627e4c25335a/go.mod h1:JG1sdvGTKWwe/oH3/3UKQ26vfcHIN//7fwEJhoqaBcM= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20260218203240-3dfff04db8fa h1:Zt3DZoOFFYkKhDT3v7Lm9FDMEV06GpzjG2jrqW+QTE0= golang.org/x/exp v0.0.0-20260218203240-3dfff04db8fa/go.mod h1:K79w1Vqn7PoiZn+TkNpx3BUWUQksGO3JcVX6qIjytmA= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8= golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4= golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k= golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk= -golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k= golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/bindings/go/scip/parse.go b/bindings/go/scip/parse.go index 023d9a36..e44867a3 100644 --- a/bindings/go/scip/parse.go +++ b/bindings/go/scip/parse.go @@ -2,9 +2,10 @@ package scip import ( "context" + "errors" + "fmt" "io" - "github.com/cockroachdb/errors" "google.golang.org/protobuf/encoding/protowire" "google.golang.org/protobuf/proto" ) @@ -39,26 +40,26 @@ func (pi *IndexVisitor) ParseStreaming(ctx context.Context, r io.Reader) error { return nil } if err != nil { - return errors.Wrapf(err, "failed to read from index reader: %w") + return fmt.Errorf("failed to read from index reader: %w", err) } if numRead == 0 { return errors.New("read 0 bytes from index") } fieldNumber, fieldType, errCode := protowire.ConsumeTag(tagBuf) if errCode < 0 { - return errors.Wrap(protowire.ParseError(errCode), "failed to consume tag") + return fmt.Errorf("failed to consume tag: %w", protowire.ParseError(errCode)) } switch fieldNumber { // As per scip.proto, all of Metadata, Document and SymbolInformation are sub-messages case metadataFieldNumber, documentsFieldNumber, externalSymbolsFieldNumber: if fieldType != protowire.BytesType { - return errors.Newf("expected LEN type tag for %s", indexFieldName(fieldNumber)) + return fmt.Errorf("expected LEN type tag for %s", indexFieldName(fieldNumber)) } lenBuf = lenBuf[:0] dataLenUint, err := readVarint(r, &lenBuf) dataLen := int(dataLenUint) if err != nil { - return errors.Wrapf(err, "failed to read length for %s", indexFieldName(fieldNumber)) + return fmt.Errorf("failed to read length for %s: %w", indexFieldName(fieldNumber), err) } if dataLen > cap(dataBuf) { dataBuf = make([]byte, dataLen) @@ -72,10 +73,10 @@ func (pi *IndexVisitor) ParseStreaming(ctx context.Context, r io.Reader) error { if dataLen > 0 { numRead, err := io.ReadAtLeast(r, dataBuf, dataLen) if err != nil { - return errors.Wrapf(err, "failed to read data for %s", indexFieldName(fieldNumber)) + return fmt.Errorf("failed to read data for %s: %w", indexFieldName(fieldNumber), err) } if numRead != dataLen { - return errors.Newf( + return fmt.Errorf( "expected to read %d bytes based on LEN but read %d bytes", dataLen, numRead) } } @@ -83,7 +84,7 @@ func (pi *IndexVisitor) ParseStreaming(ctx context.Context, r io.Reader) error { if pi.VisitMetadata != nil { m := Metadata{} if err := proto.Unmarshal(dataBuf, &m); err != nil { - return errors.Wrapf(err, "failed to read %s", indexFieldName(fieldNumber)) + return fmt.Errorf("failed to read %s: %w", indexFieldName(fieldNumber), err) } if err := pi.VisitMetadata(ctx, &m); err != nil { return err @@ -93,7 +94,7 @@ func (pi *IndexVisitor) ParseStreaming(ctx context.Context, r io.Reader) error { if pi.VisitDocument != nil { d := Document{} if err := proto.Unmarshal(dataBuf, &d); err != nil { - return errors.Wrapf(err, "failed to read %s", indexFieldName(fieldNumber)) + return fmt.Errorf("failed to read %s: %w", indexFieldName(fieldNumber), err) } if err := pi.VisitDocument(ctx, &d); err != nil { return err @@ -103,18 +104,18 @@ func (pi *IndexVisitor) ParseStreaming(ctx context.Context, r io.Reader) error { if pi.VisitExternalSymbol != nil { s := SymbolInformation{} if err := proto.Unmarshal(dataBuf, &s); err != nil { - return errors.Wrapf(err, "failed to read %s", indexFieldName(fieldNumber)) + return fmt.Errorf("failed to read %s: %w", indexFieldName(fieldNumber), err) } if err := pi.VisitExternalSymbol(ctx, &s); err != nil { return err } } } else { - return errors.Newf( + return fmt.Errorf( "added new field with number: %v in scip.Index but missing unmarshaling code", fieldNumber) } default: - return errors.Newf( + return fmt.Errorf( "added new field with number: %v in scip.Index but forgot to update streaming parser", fieldNumber) } } @@ -135,10 +136,10 @@ func readVarint(r io.Reader, scratchBuf *[]byte) (uint64, error) { for i := 0; i < cap(*scratchBuf); i++ { numRead, err := r.Read(nextByteBuf) if err != nil { - return 0, errors.Wrapf(err, "failed to read %d-th byte of Varint. soFar: %v", i, scratchBuf) + return 0, fmt.Errorf("failed to read %d-th byte of Varint. soFar: %v: %w", i, scratchBuf, err) } if numRead == 0 { - return 0, errors.Newf("failed to read %d-th byte of Varint. soFar: %v", scratchBuf) + return 0, fmt.Errorf("failed to read %d-th byte of Varint. soFar: %v", i, scratchBuf) } nextByte := nextByteBuf[0] *scratchBuf = append(*scratchBuf, nextByte) diff --git a/bindings/go/scip/symbol_parser.go b/bindings/go/scip/symbol_parser.go index 2ff94ce6..1d337d8c 100644 --- a/bindings/go/scip/symbol_parser.go +++ b/bindings/go/scip/symbol_parser.go @@ -4,7 +4,6 @@ import ( "fmt" "strings" - "github.com/cockroachdb/errors" "github.com/sourcegraph/beaut" ) @@ -364,9 +363,9 @@ const ( func (z *symbolParserV2) error(e errorCase, expectedByte byte, what parseCtx) error { switch e { case errorCaseEmptyIdent: - return errors.Newf("failed to parse: %q (context: %v)", z.SymbolString, what) + return fmt.Errorf("failed to parse: %q (context: %v)", z.SymbolString, what) case errorCaseByteNotFound: - return errors.Newf("failed to parse: %q (expected byte: %c, context: %v)", z.SymbolString, rune(expectedByte), what) + return fmt.Errorf("failed to parse: %q (expected byte: %c, context: %v)", z.SymbolString, rune(expectedByte), what) default: panic(fmt.Sprintf("unknown error case: %v", e)) } diff --git a/bindings/go/scip/testutil/format.go b/bindings/go/scip/testutil/format.go index 1f36a743..b456b9b1 100644 --- a/bindings/go/scip/testutil/format.go +++ b/bindings/go/scip/testutil/format.go @@ -1,6 +1,8 @@ package testutil import ( + "errors" + "fmt" "log" "net/url" "os" @@ -8,8 +10,6 @@ import ( "sort" "strings" - "github.com/cockroachdb/errors" - "github.com/sourcegraph/scip/bindings/go/scip" ) @@ -43,9 +43,9 @@ func FormatSnapshots( snapshot, err := FormatSnapshot(document, commentSyntax, symbolFormatter, sourceFilePath) err = symbolFormatter.OnError(err) if err != nil { - documentErrors = errors.CombineErrors( + documentErrors = errors.Join( documentErrors, - errors.Wrap(err, document.RelativePath), + fmt.Errorf("%s: %w", document.RelativePath, err), ) } sourceFile := scip.NewSourceFile(sourceFilePath, @@ -81,7 +81,7 @@ func FormatSnapshot( formatSymbol := func(symbol string) string { formatted, err := formatter.Format(symbol) if err != nil { - formattingError = errors.CombineErrors(formattingError, errors.Wrapf(err, symbol)) + formattingError = errors.Join(formattingError, fmt.Errorf("%s: %w", symbol, err)) return symbol } return formatted From eebee7ba66cc3654a961e1661c2c4718c0a2f511 Mon Sep 17 00:00:00 2001 From: jupblb Date: Thu, 26 Feb 2026 11:25:36 +0100 Subject: [PATCH 2/4] bindings/go/scip: replace golang.org/x/exp/slices with stdlib slices The slices package has been in stdlib since Go 1.21. This removes the golang.org/x/exp dependency from bindings/go/scip/go.mod. --- bindings/go/scip/go.mod | 1 - bindings/go/scip/go.sum | 2 -- bindings/go/scip/testutil/test_runner.go | 2 +- bindings/go/scip/testutil/test_runner_test.go | 3 +-- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/bindings/go/scip/go.mod b/bindings/go/scip/go.mod index 64488ca3..34cfda36 100644 --- a/bindings/go/scip/go.mod +++ b/bindings/go/scip/go.mod @@ -6,7 +6,6 @@ require ( github.com/fatih/color v1.18.0 github.com/hexops/gotextdiff v1.0.3 github.com/sourcegraph/beaut v0.0.0-20240611013027-627e4c25335a - golang.org/x/exp v0.0.0-20260218203240-3dfff04db8fa google.golang.org/protobuf v1.36.6 ) diff --git a/bindings/go/scip/go.sum b/bindings/go/scip/go.sum index 27f51736..0d974581 100644 --- a/bindings/go/scip/go.sum +++ b/bindings/go/scip/go.sum @@ -34,8 +34,6 @@ github.com/sourcegraph/beaut v0.0.0-20240611013027-627e4c25335a h1:j/CQ27s679M9w github.com/sourcegraph/beaut v0.0.0-20240611013027-627e4c25335a/go.mod h1:JG1sdvGTKWwe/oH3/3UKQ26vfcHIN//7fwEJhoqaBcM= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -golang.org/x/exp v0.0.0-20260218203240-3dfff04db8fa h1:Zt3DZoOFFYkKhDT3v7Lm9FDMEV06GpzjG2jrqW+QTE0= -golang.org/x/exp v0.0.0-20260218203240-3dfff04db8fa/go.mod h1:K79w1Vqn7PoiZn+TkNpx3BUWUQksGO3JcVX6qIjytmA= golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8= golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w= golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4= diff --git a/bindings/go/scip/testutil/test_runner.go b/bindings/go/scip/testutil/test_runner.go index ea20ed06..cce86c2c 100644 --- a/bindings/go/scip/testutil/test_runner.go +++ b/bindings/go/scip/testutil/test_runner.go @@ -7,10 +7,10 @@ import ( "io/fs" "os" "path/filepath" + "slices" "strings" "github.com/fatih/color" - "golang.org/x/exp/slices" "github.com/sourcegraph/scip/bindings/go/scip" ) diff --git a/bindings/go/scip/testutil/test_runner_test.go b/bindings/go/scip/testutil/test_runner_test.go index 3bc83860..00f8b71b 100644 --- a/bindings/go/scip/testutil/test_runner_test.go +++ b/bindings/go/scip/testutil/test_runner_test.go @@ -1,10 +1,9 @@ package testutil import ( + "slices" "testing" - "golang.org/x/exp/slices" - "github.com/stretchr/testify/require" ) From 63e93bf259ebd9ba9e9f78ea044aaf38da3189ff Mon Sep 17 00:00:00 2001 From: jupblb Date: Thu, 26 Feb 2026 12:04:12 +0100 Subject: [PATCH 3/4] bindings/go/scip: remove autogold/v2 dependency Replace autogold snapshot assertions with require.Equal in source_file_test.go and position_test.go. This removes autogold/v2 and its 6 transitive indirect deps (valast, lockfile, x/mod, x/sync, x/tools, gofumpt). --- bindings/go/scip/go.mod | 9 ++------ bindings/go/scip/go.sum | 19 +---------------- bindings/go/scip/position_test.go | 32 +++++++++++++--------------- bindings/go/scip/source_file_test.go | 19 ++++++++--------- 4 files changed, 27 insertions(+), 52 deletions(-) diff --git a/bindings/go/scip/go.mod b/bindings/go/scip/go.mod index 34cfda36..7322752b 100644 --- a/bindings/go/scip/go.mod +++ b/bindings/go/scip/go.mod @@ -12,22 +12,17 @@ require ( require ( github.com/google/go-cmp v0.7.0 github.com/google/gofuzz v1.2.0 - github.com/hexops/autogold/v2 v2.3.1 github.com/stretchr/testify v1.11.1 pgregory.net/rapid v1.1.0 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect - github.com/hexops/valast v1.5.0 // indirect + github.com/kr/text v0.2.0 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/nightlyone/lockfile v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/mod v0.33.0 // indirect - golang.org/x/sync v0.19.0 // indirect + github.com/rogpeppe/go-internal v1.14.1 // indirect golang.org/x/sys v0.41.0 // indirect - golang.org/x/tools v0.42.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - mvdan.cc/gofumpt v0.9.2 // indirect ) diff --git a/bindings/go/scip/go.sum b/bindings/go/scip/go.sum index 0d974581..ebb991f1 100644 --- a/bindings/go/scip/go.sum +++ b/bindings/go/scip/go.sum @@ -1,21 +1,14 @@ +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= -github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI= -github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/hexops/autogold v0.8.1 h1:wvyd/bAJ+Dy+DcE09BoLk6r4Fa5R5W+O+GUzmR985WM= -github.com/hexops/autogold v0.8.1/go.mod h1:97HLDXyG23akzAoRYJh/2OBs3kd80eHyKPvZw0S5ZBY= -github.com/hexops/autogold/v2 v2.3.1 h1:GcDwp9TkPkDG/wVodudePKPG8HbvEA8o8Z9hySIuAC4= -github.com/hexops/autogold/v2 v2.3.1/go.mod h1:1vQ1sj0yXQNn8VOlQeefQPXTLr9Qy9cf8pMDanZ4Gmo= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= -github.com/hexops/valast v1.5.0 h1:FBTuvVi0wjTngtXJRZXMbkN/Dn6DgsUsBwch2DUJU8Y= -github.com/hexops/valast v1.5.0/go.mod h1:Jcy1pNH7LNraVaAZDLyv21hHg2WBv9Nf9FL6fGxU7o4= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -24,8 +17,6 @@ github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHP github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/nightlyone/lockfile v1.0.0 h1:RHep2cFKK4PonZJDdEl4GmkabuhbsRMgk/k3uAmxBiA= -github.com/nightlyone/lockfile v1.0.0/go.mod h1:rywoIealpdNse2r832aiD9jRk8ErCatROs6LzC841CI= 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/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= @@ -34,15 +25,9 @@ github.com/sourcegraph/beaut v0.0.0-20240611013027-627e4c25335a h1:j/CQ27s679M9w github.com/sourcegraph/beaut v0.0.0-20240611013027-627e4c25335a/go.mod h1:JG1sdvGTKWwe/oH3/3UKQ26vfcHIN//7fwEJhoqaBcM= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8= -golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w= -golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4= -golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k= golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= -golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k= -golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0= google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -50,7 +35,5 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -mvdan.cc/gofumpt v0.9.2 h1:zsEMWL8SVKGHNztrx6uZrXdp7AX8r421Vvp23sz7ik4= -mvdan.cc/gofumpt v0.9.2/go.mod h1:iB7Hn+ai8lPvofHd9ZFGVg2GOr8sBUw1QUWjNbmIL/s= pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw= pgregory.net/rapid v1.1.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= diff --git a/bindings/go/scip/position_test.go b/bindings/go/scip/position_test.go index a5f33540..58de1123 100644 --- a/bindings/go/scip/position_test.go +++ b/bindings/go/scip/position_test.go @@ -3,8 +3,6 @@ package scip import ( "testing" - "github.com/hexops/autogold/v2" - "github.com/stretchr/testify/require" "pgregory.net/rapid" ) @@ -160,7 +158,7 @@ func TestCompareReverse(t *testing.T) { func TestNewRange_UnitTests(t *testing.T) { type testCase struct { input []int32 - expected autogold.Value + expected result } type result struct { range_ Range @@ -169,58 +167,58 @@ func TestNewRange_UnitTests(t *testing.T) { testCases := []testCase{ { input: nil, - expected: autogold.Expect(result{err: "incorrect length"}), + expected: result{err: "incorrect length"}, }, { input: []int32{3}, - expected: autogold.Expect(result{err: "incorrect length"}), + expected: result{err: "incorrect length"}, }, { input: []int32{3, 3}, - expected: autogold.Expect(result{err: "incorrect length"}), + expected: result{err: "incorrect length"}, }, { input: []int32{12, 0, 14}, - expected: autogold.Expect(result{range_: Range{ + expected: result{range_: Range{ Start: Position{Line: 12}, End: Position{ Line: 12, Character: 14, }, - }}), + }}, }, { input: []int32{12, 14, 0}, - expected: autogold.Expect(result{err: "end before start"}), + expected: result{err: "end before start"}, }, { input: []int32{12, 14, 0}, - expected: autogold.Expect(result{err: "end before start"}), + expected: result{err: "end before start"}, }, { input: []int32{12, 15, 14, 0}, - expected: autogold.Expect(result{range_: Range{ + expected: result{range_: Range{ Start: Position{ Line: 12, Character: 15, }, End: Position{Line: 14}, - }}), + }}, }, { input: []int32{12, 0, 12, 0}, - expected: autogold.Expect(result{range_: Range{ + expected: result{range_: Range{ Start: Position{Line: 12}, End: Position{Line: 12}, - }}), + }}, }, { input: []int32{12, 0, 13, 1, 4}, - expected: autogold.Expect(result{err: "incorrect length"}), + expected: result{err: "incorrect length"}, }, { input: []int32{3, -1, 4}, - expected: autogold.Expect(result{err: "negative offsets"}), + expected: result{err: "negative offsets"}, }, } @@ -231,7 +229,7 @@ func TestNewRange_UnitTests(t *testing.T) { if err != nil { errStr = err.Error() } - tc.expected.Equal(t, result{range_: r, err: errStr}) + require.Equal(t, tc.expected, result{range_: r, err: errStr}) }, "panicked for input: %v", tc.input) } } diff --git a/bindings/go/scip/source_file_test.go b/bindings/go/scip/source_file_test.go index bad95768..841ab157 100644 --- a/bindings/go/scip/source_file_test.go +++ b/bindings/go/scip/source_file_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/hexops/autogold/v2" + "github.com/stretchr/testify/require" ) const testFileContents = `Mary had a little lamb, @@ -14,20 +14,19 @@ The lamb was sure to go. ` func TestRangeText(t *testing.T) { - // Update expect values with `go test ./bindings/go/scip -update` testCases := []struct { range_ []int32 - expect autogold.Value + expect string }{ - {range_: []int32{0, 0, 0, 0}, expect: autogold.Expect("")}, - {range_: []int32{0, 0, 0, 8}, expect: autogold.Expect("Mary had")}, - {range_: []int32{0, 0, 1, 0}, expect: autogold.Expect("Mary had a little lamb,\n")}, - {range_: []int32{0, 0, 1, 10}, expect: autogold.Expect("Mary had a little lamb,\nIts fleece")}, - {range_: []int32{0, 0, 4, 0}, expect: autogold.Expect(`Mary had a little lamb, + {range_: []int32{0, 0, 0, 0}, expect: ""}, + {range_: []int32{0, 0, 0, 8}, expect: "Mary had"}, + {range_: []int32{0, 0, 1, 0}, expect: "Mary had a little lamb,\n"}, + {range_: []int32{0, 0, 1, 10}, expect: "Mary had a little lamb,\nIts fleece"}, + {range_: []int32{0, 0, 4, 0}, expect: `Mary had a little lamb, Its fleece was white as snow. And everywhere that Mary went, The lamb was sure to go. -`)}, +`}, } sourceFile := NewSourceFile("", "", testFileContents) @@ -36,7 +35,7 @@ The lamb was sure to go. r := testCase.range_ range_ := Range{Start: Position{Line: r[0], Character: r[1]}, End: Position{Line: r[2], Character: r[3]}} t.Run(fmt.Sprintf("%v", range_), func(t *testing.T) { - testCase.expect.Equal(t, sourceFile.RangeText(range_)) + require.Equal(t, testCase.expect, sourceFile.RangeText(range_)) }) } } From d2325435c628507ce0428250ec9e0d7a55e5e1e9 Mon Sep 17 00:00:00 2001 From: jupblb Date: Thu, 26 Feb 2026 12:16:41 +0100 Subject: [PATCH 4/4] Fix position_test.go type ordering and update vendor hash --- bindings/go/scip/position_test.go | 8 ++++---- checks.nix | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bindings/go/scip/position_test.go b/bindings/go/scip/position_test.go index 58de1123..95f31efc 100644 --- a/bindings/go/scip/position_test.go +++ b/bindings/go/scip/position_test.go @@ -156,14 +156,14 @@ func TestCompareReverse(t *testing.T) { } func TestNewRange_UnitTests(t *testing.T) { - type testCase struct { - input []int32 - expected result - } type result struct { range_ Range err string } + type testCase struct { + input []int32 + expected result + } testCases := []testCase{ { input: nil, diff --git a/checks.nix b/checks.nix index 20cf5b1b..117cde0e 100644 --- a/checks.nix +++ b/checks.nix @@ -29,7 +29,7 @@ inherit version; src = ./.; modRoot = "./bindings/go/scip"; - vendorHash = "sha256-l2AcFUUmO44/Q2nwtOVuGu3ffP/dpIYaa1AlKHoHSq8="; + vendorHash = "sha256-6n1H+0t+CWJXo8CYb37NNoLi+ONVoaiDvyQZMxIRByo="; env.GOWORK = "off"; buildTags = [ "asserts" ]; subPackages = [