Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions internal/compiler/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions internal/rpc/errors.go
Original file line number Diff line number Diff line change
@@ -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()
7 changes: 1 addition & 6 deletions internal/rpc/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@ 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...)

switch status.Convert(err).Code() {
case codes.OK:
return nil
case codes.Unauthenticated:
return status.New(codes.Unauthenticated, errMessageUnauthenticated).Err()
return ErrUnauthenticated
default:
return err
}
Expand Down