Update CLI to provide better error when passing incorrect env name#2301
Draft
marcuskohlberg wants to merge 1 commit intomainfrom
Draft
Update CLI to provide better error when passing incorrect env name#2301marcuskohlberg wants to merge 1 commit intomainfrom
marcuskohlberg wants to merge 1 commit intomainfrom
Conversation
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.
Fixes: #2252
When an invalid environment name is passed via
--envtoencore db shell,db proxy, ordb conn-uri, the CLI now returns a clear error listing the available environments, instead of the misleading "database not found" error.Problem
Running
encore db shell appDB --env=developmentwhen the correct environment slug is staging produces:psql: error: connection to server at "127.0.0.1", port 58103 failed: FATAL: database appDB not foundThis is confusing because the database does exist — the environment name is wrong.
The misleading error is caused by the platform API returning a 404 for the invalid environment, which the CLI blindly converts into a `DatabaseNotFoundError? .
Solution
Added upfront environment validation in
DBConnectandDBProxyby callingplatform.ListEnvsbefore setting up the database proxy. If the environment slug doesn't match any known environment, the CLI now returns:could not connect to the database for service appDB: environment "development" not found; available environments for this app are: staging, prodIf the
ListEnvscall itself fails (e.g. due to network issues), validation is skipped gracefully and the existing behavior is preserved.