Skip to content

Update CLI to provide better error when passing incorrect env name#2301

Draft
marcuskohlberg wants to merge 1 commit intomainfrom
climsg
Draft

Update CLI to provide better error when passing incorrect env name#2301
marcuskohlberg wants to merge 1 commit intomainfrom
climsg

Conversation

@marcuskohlberg
Copy link
Member

Fixes: #2252

When an invalid environment name is passed via --env to encore db shell, db proxy, or db 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=development when the correct environment slug is staging produces:
psql: error: connection to server at "127.0.0.1", port 58103 failed: FATAL: database appDB not found

This 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 DBConnect and DBProxy by calling platform.ListEnvs before 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, prod

If the ListEnvs call itself fails (e.g. due to network issues), validation is skipped gracefully and the existing behavior is preserved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Encore CLI database shell command gives confusing error message

1 participant