feat: Improve messaging for common cloud config and rpc errors#2885
Merged
kyleconroy merged 2 commits intomainfrom Oct 19, 2023
Merged
feat: Improve messaging for common cloud config and rpc errors#2885kyleconroy merged 2 commits intomainfrom
kyleconroy merged 2 commits intomainfrom
Conversation
1. Add a UnaryClientInterceptor for all gRPC client connections to catch and rewrite unauthenticated error messages 2. Put the sqlc auth token in the config struct, and add simple validation 3. Add more explanatory error messages in cases where users try to use cloud features without the proper configuration 4. Prevent sending the SQLC_AUTH_TOKEN env var to plugins Resolves #2881 Resolves #2881
andrewmbenton
commented
Oct 19, 2023
Comment on lines
+9
to
+17
| func (c *Config) addEnvVars() error { | ||
| authToken := os.Getenv("SQLC_AUTH_TOKEN") | ||
| if authToken != "" && !strings.HasPrefix(authToken, "sqlc_") { | ||
| return fmt.Errorf("$SQLC_AUTH_TOKEN doesn't start with \"sqlc_\"") | ||
| } | ||
| c.Cloud.AuthToken = authToken | ||
|
|
||
| return nil | ||
| } |
Collaborator
Author
There was a problem hiding this comment.
I wanted to get away from calling os.Getenv() all over the place, but I'm not sure this (adding fields to Config struct and then populating after parse) is the best way to do it.
Collaborator
There was a problem hiding this comment.
I think as long as we only do this in one place, here in the config package, it's okay.
andrewmbenton
commented
Oct 19, 2023
Comment on lines
+40
to
+42
| if key == "SQLC_AUTH_TOKEN" { | ||
| continue | ||
| } |
Collaborator
Author
There was a problem hiding this comment.
We don't really need this, it just seemed like a reasonable thing to do (prevent users from sending their auth tokens to plugins).
kyleconroy
approved these changes
Oct 19, 2023
alfonsodev
pushed a commit
to ExponentiaTeam/sqlc
that referenced
this pull request
Oct 13, 2025
…dev#2885) * feat: Improve messaging for common cloud config and rpc errors 1. Add a UnaryClientInterceptor for all gRPC client connections to catch and rewrite unauthenticated error messages 2. Put the sqlc auth token in the config struct, and add simple validation 3. Add more explanatory error messages in cases where users try to use cloud features without the proper configuration 4. Prevent sending the SQLC_AUTH_TOKEN env var to plugins Resolves sqlc-dev#2881 * Don't continue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This turned out to have more changes than I expected. A high-level list follows. There are definitely some style choices I made here that I'm not at all attached to, so feel free to recommend changes.
Add a UnaryClientInterceptor for all gRPC client connections to catch and rewrite unauthenticated error messages
Put the sqlc auth token in the config struct, and add simple validation
Add more explanatory error messages in cases where users try to use cloud features without the proper configuration
Prevent sending the SQLC_AUTH_TOKEN env var to plugins
Resolves #2881