Skip to content

config edit: allow editing malformed spack.yaml file#51088

Merged
alalazo merged 4 commits intodevelopfrom
bugfix/config-edit-malformed-spack-yaml
Aug 18, 2025
Merged

config edit: allow editing malformed spack.yaml file#51088
alalazo merged 4 commits intodevelopfrom
bugfix/config-edit-malformed-spack-yaml

Conversation

@becker33
Copy link
Copy Markdown
Member

Fixes #41470 (spack config edit fails if the spack.yaml file is malformed).

When spack.yaml generates a ConfigFormatError and the command is spack config edit, we cache that error as spack.environment.environment._active_environment_error.

In spack config edit, raise if there is an active environment error and the command would not edit the spack.yaml file. If it is editing the spack.yaml file, get the filename from the cached error since there is no properly active environment.

@becker33 becker33 added the v1.0.1 PRs to backport for v1.0.1 label Jul 31, 2025
@alalazo alalazo self-requested a review August 6, 2025 12:59
Copy link
Copy Markdown
Member

@alalazo alalazo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to:

$ spack env activate --temp
$ spack config edit
# introduce syntax error and close file
$ spack config edit

This PR doesn't seem to solve the issue for me:
Screenshot from 2025-08-06 15-01-32

@alalazo alalazo self-assigned this Aug 6, 2025
@becker33
Copy link
Copy Markdown
Member Author

becker33 commented Aug 8, 2025

@alalazo I had not realized we raise different error messages for yaml format errors and schema validation errors (even more fun, we call the latter ConfigFormatError).

I think this should be ready now. It looks like other spots that are trying to catch all environment yaml errors catch the same two errors I'm now catching for this.

Signed-off-by: Gregory Becker <[email protected]>
@alecbcs alecbcs added v1.0.2 PRs / Bug fixes to backport for v1.0.2 and removed v1.0.1 PRs to backport for v1.0.1 labels Aug 11, 2025
Copy link
Copy Markdown
Member

@alalazo alalazo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed the PR is now working on the previous use case. Can we add a test in shell-tests that checks something similar to:

$ EDITOR=cat spack config edit
==> Error: Invalid environment configuration detected: error parsing YAML: near /tmp/spack-mou8_0x6/spack.yaml, 6, 9: expected ',' or ']', but got ':'
# This is a Spack Environment file.
#
# It describes a set of packages to be installed, along with
# configuration settings.
spack:
  # add package specs to the `specs` list
  specs: [
  view: true
  concretizer:
    unify: true
$ echo $?
0

?

@alalazo alalazo enabled auto-merge (squash) August 18, 2025 10:30
@alalazo alalazo merged commit e2046e3 into develop Aug 18, 2025
31 checks passed
@alalazo alalazo deleted the bugfix/config-edit-malformed-spack-yaml branch August 18, 2025 11:28
@alalazo alalazo mentioned this pull request Aug 22, 2025
26 tasks
alalazo pushed a commit that referenced this pull request Aug 22, 2025
alalazo pushed a commit that referenced this pull request Aug 22, 2025
alalazo pushed a commit that referenced this pull request Aug 22, 2025
Signed-off-by: Gregory Becker <[email protected]>
Signed-off-by: Massimiliano Culpo <[email protected]>
haampie pushed a commit that referenced this pull request Sep 12, 2025
Signed-off-by: Gregory Becker <[email protected]>
Signed-off-by: Massimiliano Culpo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v1.0.2 PRs / Bug fixes to backport for v1.0.2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Once you have a syntax error in spack.yaml, you can't use 'spack config edit' to fix it.

3 participants