From 9dd02cad0a87adc2ac5b19d9c9f51851ec492f67 Mon Sep 17 00:00:00 2001 From: neilotoole Date: Mon, 18 Nov 2024 00:28:10 -0700 Subject: [PATCH] errcheck is being newly cranky about type assertions --- .golangci.yml | 2 +- cli/run/run.go | 2 +- drivers/sqlite3/internal/sqlparser/create_table.go | 2 +- libsq/ast/ast.go | 2 +- libsq/ast/inspector.go | 2 +- libsq/core/errz/errz.go | 2 +- libsq/core/errz/errz_test.go | 2 +- libsq/core/errz/internal_test.go | 6 +++--- libsq/core/execz/execz.go | 2 +- libsq/core/ioz/httpz/httpz.go | 4 ++-- libsq/core/ioz/ioz.go | 2 +- libsq/core/sqlz/connector.go | 2 +- libsq/files/internal/downloader/downloader_test.go | 2 +- libsq/files/internal/downloader/handler.go | 2 +- 14 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index c4508072e..86581575f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -59,7 +59,7 @@ linters-settings: # Report about not checking of errors in type assertions: `a := b.(MyStruct)`. # Such cases aren't reported by default. # Default: false - check-type-assertions: true + check-type-assertions: false exhaustive: # Program elements to check for exhaustiveness. diff --git a/cli/run/run.go b/cli/run/run.go index 029802732..a2bb88363 100644 --- a/cli/run/run.go +++ b/cli/run/run.go @@ -36,7 +36,7 @@ func NewContext(ctx context.Context, ru *Run) context.Context { // FromContext extracts the Run added to ctx via NewContext. func FromContext(ctx context.Context) *Run { - return ctx.Value(runKey{}).(*Run) + return ctx.Value(runKey{}).(*Run) //nolint:errcheck } // Run is a container for injectable resources passed diff --git a/drivers/sqlite3/internal/sqlparser/create_table.go b/drivers/sqlite3/internal/sqlparser/create_table.go index 87897c0b0..008343969 100644 --- a/drivers/sqlite3/internal/sqlparser/create_table.go +++ b/drivers/sqlite3/internal/sqlparser/create_table.go @@ -30,7 +30,7 @@ func parseCreateTableStmt(input string) (*sqlite.Create_table_stmtContext, error return nil, errz.Err(err) } - return qCtx.(*sqlite.Create_table_stmtContext), nil + return qCtx.(*sqlite.Create_table_stmtContext), nil //nolint:errcheck } // ExtractTableIdentFromCreateTableStmt extracts table name (and the diff --git a/libsq/ast/ast.go b/libsq/ast/ast.go index 0c66f3ce7..f1c30fa82 100644 --- a/libsq/ast/ast.go +++ b/libsq/ast/ast.go @@ -54,7 +54,7 @@ func buildAST(log *slog.Logger, query slq.IQueryContext) (*AST, error) { tree := &parseTreeVisitor{log: log} if err := q.Accept(tree); err != nil { - return nil, err.(error) + return nil, err.(error) //nolint:errcheck } visitors := []struct { diff --git a/libsq/ast/inspector.go b/libsq/ast/inspector.go index e0d1527a0..527195e0f 100644 --- a/libsq/ast/inspector.go +++ b/libsq/ast/inspector.go @@ -217,7 +217,7 @@ func (in *Inspector) FindTableSegments() []*SegmentNode { func (in *Inspector) FindFirstHandle() (handle string) { nodes := in.FindNodes(typeHandleNode) if len(nodes) > 0 { - handle = nodes[0].(*HandleNode).Handle() + handle = nodes[0].(*HandleNode).Handle() //nolint:errcheck return handle } diff --git a/libsq/core/errz/errz.go b/libsq/core/errz/errz.go index 9463e6b70..77439842c 100644 --- a/libsq/core/errz/errz.go +++ b/libsq/core/errz/errz.go @@ -313,7 +313,7 @@ func WithExitCode(err error, code int) error { var _ ExitCoder = (*exitCoder)(nil) -type exitCoder struct { +type exitCoder struct { //nolint:errname errz code int } diff --git a/libsq/core/errz/errz_test.go b/libsq/core/errz/errz_test.go index 1cbcef97d..b45ba9c75 100644 --- a/libsq/core/errz/errz_test.go +++ b/libsq/core/errz/errz_test.go @@ -54,7 +54,7 @@ func TestUnwrapChain(t *testing.T) { require.Equal(t, "huzzah", gotCustomErr.msg) gotUnwrap := errz.UnwrapChain(err) - require.Equal(t, *originalErr.(*customError), *gotUnwrap.(*customError)) //nolint:errorlint + require.Equal(t, *originalErr.(*customError), *gotUnwrap.(*customError)) //nolint:errorlint,errcheck } type customError struct { diff --git a/libsq/core/errz/internal_test.go b/libsq/core/errz/internal_test.go index 19609ec4b..a6d49acc9 100644 --- a/libsq/core/errz/internal_test.go +++ b/libsq/core/errz/internal_test.go @@ -11,16 +11,16 @@ import ( func TestAlienCause(t *testing.T) { err := New("boo") - cause := err.(*errz).alienCause() + cause := err.(*errz).alienCause() //nolint:errcheck require.Nil(t, cause) err = Err(context.DeadlineExceeded) - cause = err.(*errz).alienCause() + cause = err.(*errz).alienCause() //nolint:errcheck require.Equal(t, context.DeadlineExceeded, cause) err = Err(context.DeadlineExceeded) err = Wrap(err, "wrap") - cause = err.(*errz).alienCause() + cause = err.(*errz).alienCause() //nolint:errcheck require.Equal(t, context.DeadlineExceeded, cause) } diff --git a/libsq/core/execz/execz.go b/libsq/core/execz/execz.go index 42bd58349..be48024e5 100644 --- a/libsq/core/execz/execz.go +++ b/libsq/core/execz/execz.go @@ -258,7 +258,7 @@ func Exec(ctx context.Context, cmd *Cmd) (err error) { if _, ok := cmd.Stdout.(*os.File); ok && !cmd.NoProgress { bar := progress.FromContext(ctx).NewFilesizeCounter( langz.NonEmptyOf(cmd.Label, cmd.Name), - cmd.Stdout.(*os.File), + cmd.Stdout.(*os.File), //nolint:errcheck "", progress.OptTimer, ) diff --git a/libsq/core/ioz/httpz/httpz.go b/libsq/core/ioz/httpz/httpz.go index 30d0dd725..15d30bd06 100644 --- a/libsq/core/ioz/httpz/httpz.go +++ b/libsq/core/ioz/httpz/httpz.go @@ -40,9 +40,9 @@ func NewClient(opts ...Opt) *http.Client { c.Timeout = 0 var tr *http.Transport if c.Transport == nil { - tr = (http.DefaultTransport.(*http.Transport)).Clone() + tr = (http.DefaultTransport.(*http.Transport)).Clone() //nolint:errcheck } else { - tr = (c.Transport.(*http.Transport)).Clone() + tr = (c.Transport.(*http.Transport)).Clone() //nolint:errcheck } DefaultTLSVersion.apply(tr) diff --git a/libsq/core/ioz/ioz.go b/libsq/core/ioz/ioz.go index 12848c7a1..614ce5f70 100644 --- a/libsq/core/ioz/ioz.go +++ b/libsq/core/ioz/ioz.go @@ -349,7 +349,7 @@ type nopWriteCloserReaderFrom struct { func (nopWriteCloserReaderFrom) Close() error { return nil } func (c nopWriteCloserReaderFrom) ReadFrom(r io.Reader) (int64, error) { - return c.Writer.(io.ReaderFrom).ReadFrom(r) + return c.Writer.(io.ReaderFrom).ReadFrom(r) //nolint:errcheck } // DrainClose drains rc, returning the number of bytes read, and any error. diff --git a/libsq/core/sqlz/connector.go b/libsq/core/sqlz/connector.go index f2824f77b..f2b34cf41 100644 --- a/libsq/core/sqlz/connector.go +++ b/libsq/core/sqlz/connector.go @@ -66,5 +66,5 @@ type connectorCloser struct { // Close implements io.Closer. func (c connectorCloser) Close() error { - return c.impl.(io.Closer).Close() + return c.impl.(io.Closer).Close() //nolint:errcheck } diff --git a/libsq/files/internal/downloader/downloader_test.go b/libsq/files/internal/downloader/downloader_test.go index 187a53636..610c7659d 100644 --- a/libsq/files/internal/downloader/downloader_test.go +++ b/libsq/files/internal/downloader/downloader_test.go @@ -196,7 +196,7 @@ func TestCachePreservedOnFailedRefresh(t *testing.T) { sentBody = stringz.UniqSuffix("baaaaad") _, err := w.Write([]byte(sentBody)) assert.NoError(t, err) - w.(http.Flusher).Flush() + w.(http.Flusher).Flush() //nolint:errcheck time.Sleep(time.Millisecond * 10) srvr.CloseClientConnections() // The client should get an io.ErrUnexpectedEOF. diff --git a/libsq/files/internal/downloader/handler.go b/libsq/files/internal/downloader/handler.go index 987c4059d..ae8e6db6b 100644 --- a/libsq/files/internal/downloader/handler.go +++ b/libsq/files/internal/downloader/handler.go @@ -61,7 +61,7 @@ func (sh *SinkHandler) Reset() { sh.Downloaded = nil for _, stream := range sh.Streams { - _ = stream.Source().(io.Closer).Close() + _ = stream.Source().(io.Closer).Close() //nolint:errcheck } sh.Streams = nil