Skip to content

Errors during environment creation should cause broken environment to be deleted #2102

@flying-sheep

Description

@flying-sheep

Problem

Sometimes it happens that hatch env create ... or hatch test or hatch run ... encounter an error while creating (or more rarely when synchronizing) the environment, because of something like a dependency resolution or build error, {pre,post}-install-commands failing, and so on.

If I don’t immediately resolve the issue, that causes a broken environment to remain, with nothing or only a few packages installed into it.

Subsequent commands will try to interact with that environment and fail in unexpected ways or generate results that don’t reflect what would happen had the environment creation fully succeeded.

Proposed solution

I was thinking of two solutions:

  1. Hatch should delete environments if they can’t be fully created or synchronized without error, or
  2. Hatch should mark them in a way that subsequent commands trying to use it try to re-create them or just error with a message that mentions the user could try hatch env remove <env-name>

The second solution doesn’t interact with other tools trying to use the environment (like language servers), but it has the advantage of users being able to inspect the broken environment, in case their content is related to the error. So I think the best solution would be a modified 1.:

  • Environment-syncing commands should delete environments when their setup causes an error, unless --keep-env (or so) is specified, which allows users to opt into keeping broken envs around for debugging purposes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions