diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c8bccb6bfc..f6eba6dcfe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,7 +57,7 @@ jobs: run: go install ./... - name: test ./... - run: gotestsum --junitfile junit.xml -- --tags=examples ./... + run: gotestsum --junitfile junit.xml -- --tags=examples -timeout 20m ./... env: MYSQL_DATABASE: mysql MYSQL_HOST: localhost diff --git a/internal/compiler/compile.go b/internal/compiler/compile.go index 9f4a5170ef..19b737257c 100644 --- a/internal/compiler/compile.go +++ b/internal/compiler/compile.go @@ -11,6 +11,7 @@ import ( "github.com/sqlc-dev/sqlc/internal/migrations" "github.com/sqlc-dev/sqlc/internal/multierr" "github.com/sqlc-dev/sqlc/internal/opts" + "github.com/sqlc-dev/sqlc/internal/rpc" "github.com/sqlc-dev/sqlc/internal/source" "github.com/sqlc-dev/sqlc/internal/sql/ast" "github.com/sqlc-dev/sqlc/internal/sql/sqlerr" @@ -88,6 +89,10 @@ func (c *Compiler) parseQueries(o opts.Parser) (*Result, error) { loc = e.Location } merr.Add(filename, src, loc, err) + // If this rpc unauthenticated error bubbles up, then all future parsing/analysis will fail + if errors.Is(err, rpc.ErrUnauthenticated) { + return nil, merr + } continue } queryName := query.Metadata.Name diff --git a/internal/rpc/errors.go b/internal/rpc/errors.go new file mode 100644 index 0000000000..80953343f8 --- /dev/null +++ b/internal/rpc/errors.go @@ -0,0 +1,13 @@ +package rpc + +import ( + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +const errMessageUnauthenticated = `rpc authentication failed + +You may be using a sqlc auth token that was created for a different project, +or your auth token may have expired.` + +var ErrUnauthenticated = status.New(codes.Unauthenticated, errMessageUnauthenticated).Err() diff --git a/internal/rpc/interceptor.go b/internal/rpc/interceptor.go index b0262c09fc..ac0490bd1a 100644 --- a/internal/rpc/interceptor.go +++ b/internal/rpc/interceptor.go @@ -8,11 +8,6 @@ import ( "google.golang.org/grpc/status" ) -const errMessageUnauthenticated = `rpc authentication failed - -You may be using a sqlc auth token that was created for a different project, -or your auth token may have expired.` - func UnaryInterceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { err := invoker(ctx, method, req, reply, cc, opts...) @@ -20,7 +15,7 @@ func UnaryInterceptor(ctx context.Context, method string, req, reply interface{} case codes.OK: return nil case codes.Unauthenticated: - return status.New(codes.Unauthenticated, errMessageUnauthenticated).Err() + return ErrUnauthenticated default: return err }