Skip to content

Commit 62ee04a

Browse files
authored
build(deps): bump github.com/ccoveille/go-safecast to v2.0.0 (#574)
1 parent 022f31a commit 62ee04a

File tree

6 files changed

+29
-15
lines changed

6 files changed

+29
-15
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
github.com/authzed/grpcutil v0.0.0-20240123194739-2ea1e3d2d98b
1818
github.com/authzed/spicedb v1.45.4
1919
github.com/brianvoe/gofakeit/v6 v6.28.0
20-
github.com/ccoveille/go-safecast v1.6.1
20+
github.com/ccoveille/go-safecast/v2 v2.0.0
2121
github.com/cenkalti/backoff/v4 v4.3.0
2222
github.com/charmbracelet/lipgloss v1.1.0
2323
github.com/charmbracelet/x/term v0.2.1
@@ -135,6 +135,7 @@ require (
135135
github.com/caio/go-tdigest/v4 v4.0.1 // indirect
136136
github.com/catenacyber/perfsprint v0.9.1 // indirect
137137
github.com/ccojocar/zxcvbn-go v1.0.4 // indirect
138+
github.com/ccoveille/go-safecast v1.8.1 // indirect
138139
github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d // indirect
139140
github.com/cespare/xxhash/v2 v2.3.0 // indirect
140141
github.com/charithe/durationcheck v0.0.10 // indirect

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,8 +808,10 @@ github.com/catenacyber/perfsprint v0.9.1 h1:5LlTp4RwTooQjJCvGEFV6XksZvWE7wCOUvjD
808808
github.com/catenacyber/perfsprint v0.9.1/go.mod h1:q//VWC2fWbcdSLEY1R3l8n0zQCDPdE4IjZwyY1HMunM=
809809
github.com/ccojocar/zxcvbn-go v1.0.4 h1:FWnCIRMXPj43ukfX000kvBZvV6raSxakYr1nzyNrUcc=
810810
github.com/ccojocar/zxcvbn-go v1.0.4/go.mod h1:3GxGX+rHmueTUMvm5ium7irpyjmm7ikxYFOSJB21Das=
811-
github.com/ccoveille/go-safecast v1.6.1 h1:Nb9WMDR8PqhnKCVs2sCB+OqhohwO5qaXtCviZkIff5Q=
812-
github.com/ccoveille/go-safecast v1.6.1/go.mod h1:QqwNjxQ7DAqY0C721OIO9InMk9zCwcsO7tnRuHytad8=
811+
github.com/ccoveille/go-safecast v1.8.1 h1:RoucjfYKKcx2lFmIjRjuo8AeX9k/GaZn5SUMHlA3kMw=
812+
github.com/ccoveille/go-safecast v1.8.1/go.mod h1:QqwNjxQ7DAqY0C721OIO9InMk9zCwcsO7tnRuHytad8=
813+
github.com/ccoveille/go-safecast/v2 v2.0.0 h1:+5eyITXAUj3wMjad6cRVJKGnC7vDS55zk0INzJagub0=
814+
github.com/ccoveille/go-safecast/v2 v2.0.0/go.mod h1:JIYA4CAR33blIDuE6fSwCp2sz1oOBahXnvmdBhOAABs=
813815
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
814816
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
815817
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=

internal/cmd/restorer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99
"time"
1010

11-
"github.com/ccoveille/go-safecast"
11+
"github.com/ccoveille/go-safecast/v2"
1212
"github.com/cenkalti/backoff/v4"
1313
"github.com/mattn/go-isatty"
1414
"github.com/rs/zerolog/log"
@@ -279,7 +279,7 @@ func (r *restorer) commitStream(ctx context.Context, bulkImportClient v1.Permiss
279279

280280
// it was a successful transaction commit without duplicates
281281
if resp != nil {
282-
numLoaded, err := safecast.ToUint(resp.NumLoaded)
282+
numLoaded, err := safecast.Convert[uint](resp.NumLoaded)
283283
if err != nil {
284284
return spiceerrors.MustBugf("could not cast numLoaded to uint")
285285
}
@@ -289,7 +289,7 @@ func (r *restorer) commitStream(ctx context.Context, bulkImportClient v1.Permiss
289289
}
290290
}
291291

292-
writtenAndSkipped, err := safecast.ToInt64(r.writtenRels + r.skippedRels)
292+
writtenAndSkipped, err := safecast.Convert[int64](r.writtenRels + r.skippedRels)
293293
if err != nil {
294294
return fmt.Errorf("too many written and skipped rels for an int64")
295295
}

internal/cmd/restorer_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"testing"
66
"time"
77

8-
"github.com/ccoveille/go-safecast"
8+
"github.com/ccoveille/go-safecast/v2"
99
"github.com/stretchr/testify/require"
1010
"google.golang.org/grpc"
1111
"google.golang.org/grpc/codes"
@@ -220,7 +220,11 @@ func (m *mockClientForRestore) Send(req *v1.ImportBulkRelationshipsRequest) erro
220220

221221
for i, rel := range req.Relationships {
222222
// This is a gosec115 false positive which should be fixed in a future version.
223-
uinti, _ := safecast.ToUint(i)
223+
uinti, err := safecast.Convert[uint](i)
224+
if err != nil {
225+
// just in case to avoid accessing out of bounds in the []string
226+
uinti = 0
227+
}
224228
require.True(m.t, proto.Equal(rel, tuple.MustParseV1Rel(m.expectedRels[((m.receivedBatches-1)*m.requestedBatchSize)+uinti])))
225229
}
226230

internal/cmd/schema.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"path/filepath"
1010
"strings"
1111

12-
"github.com/ccoveille/go-safecast"
12+
"github.com/ccoveille/go-safecast/v2"
1313
"github.com/jzelinskie/cobrautil/v2"
1414
"github.com/jzelinskie/stringz"
1515
"github.com/rs/zerolog/log"
@@ -223,7 +223,7 @@ func schemaCopyCmdFunc(cmd *cobra.Command, args []string) error {
223223
}
224224

225225
func schemaWriteCmdImpl(cmd *cobra.Command, args []string, client v1.SchemaServiceClient, terminalChecker termChecker) error {
226-
stdInFd, err := safecast.ToInt(uint(os.Stdin.Fd()))
226+
stdInFd, err := safecast.Convert[int](os.Stdin.Fd())
227227
if err != nil {
228228
return err
229229
}
@@ -363,7 +363,7 @@ func determinePrefixForSchema(ctx context.Context, specifiedPrefix string, clien
363363
// Compiles an input schema written in the new composable schema syntax
364364
// and produces it as a fully-realized schema
365365
func schemaCompileCmdFunc(cmd *cobra.Command, args []string, termChecker termChecker) error {
366-
stdOutFd, err := safecast.ToInt(uint(os.Stdout.Fd()))
366+
stdOutFd, err := safecast.Convert[int](os.Stdout.Fd())
367367
if err != nil {
368368
return err
369369
}

internal/cmd/validate.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"os"
88
"strings"
99

10-
"github.com/ccoveille/go-safecast"
10+
"github.com/ccoveille/go-safecast/v2"
1111
"github.com/charmbracelet/lipgloss"
1212
"github.com/jzelinskie/cobrautil/v2"
1313
"github.com/muesli/termenv"
@@ -283,9 +283,16 @@ func outputErrorWithSource(sb *strings.Builder, validateContents []byte, errWith
283283

284284
func outputForLine(sb *strings.Builder, validateContents []byte, oneIndexedLineNumber uint64, sourceCodeString string, oneIndexedColumnPosition uint64) {
285285
lines := strings.Split(string(validateContents), "\n")
286-
// These should be fine to be zero if the cast fails.
287-
intLineNumber, _ := safecast.ToInt(oneIndexedLineNumber)
288-
intColumnPosition, _ := safecast.ToInt(oneIndexedColumnPosition)
286+
intLineNumber, err := safecast.Convert[int](oneIndexedLineNumber)
287+
if err != nil {
288+
// It's fine to be zero if the cast fails.
289+
intLineNumber = 0
290+
}
291+
intColumnPosition, err := safecast.Convert[int](oneIndexedColumnPosition)
292+
if err != nil {
293+
// It's fine to be zero if the cast fails.
294+
intColumnPosition = 0
295+
}
289296
errorLineNumber := intLineNumber - 1
290297
for i := errorLineNumber - 3; i < errorLineNumber+3; i++ {
291298
if i == errorLineNumber {

0 commit comments

Comments
 (0)