Skip to content

fix: error when invalidating a nonexistent environment#5878

Open
NishchayMahor wants to merge 1 commit into
SQLMesh:mainfrom
NishchayMahor:fix/invalidate-nonexistent-environment
Open

fix: error when invalidating a nonexistent environment#5878
NishchayMahor wants to merge 1 commit into
SQLMesh:mainfrom
NishchayMahor:fix/invalidate-nonexistent-environment

Conversation

@NishchayMahor

Copy link
Copy Markdown

What

sqlmesh invalidate ENVIRONMENT reports success even when the environment doesn't exist:

$ sqlmesh invalidate doesnotexist
Environment 'doesnotexist' invalidated.

That's misleading — a mistyped environment name looks like it worked. This checks that the environment exists first and raises a clear error with a nonzero exit code otherwise:

$ sqlmesh invalidate doesnotexist
Error: Environment 'doesnotexist' does not exist.
$ echo $?
1

How

Context.invalidate_environment now looks the environment up via state_sync.get_environment before invalidating, and raises SQLMeshError when it's absent (the CLI's @error_handler maps that to exit code 1). The message and exception match the existing "environment not found" patterns already used elsewhere in context.py.

Testing

  • New unit test test_invalidate_environment_nonexistent_raises (fails without the fix).
  • Existing test_invalidate_environment_{sync,no_sync} and the test_invalidating_environment integration test still pass.
  • Verified end to end on a fresh sqlmesh init duckdb project: nonexistent env → Error: Environment '...' does not exist. with exit code 1.

Fixes #5621

sqlmesh invalidate ENVIRONMENT reported success even when the environment
did not exist, so a mistyped name looked like it worked. Check the
environment exists first and raise a clear error (nonzero exit) otherwise.

Fixes SQLMesh#5621

Signed-off-by: Nishchay Mahor <nishchaymahor@gmail.com>
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.

sqlmesh invalidate allows invalidating nonexistent environments

1 participant