Skip to content

specs: Better error messages for badly quoted specs#41805

Merged
becker33 merged 1 commit intodevelopfrom
better-spec-query-errors
Dec 21, 2023
Merged

specs: Better error messages for badly quoted specs#41805
becker33 merged 1 commit intodevelopfrom
better-spec-query-errors

Conversation

@tgamblin
Copy link
Copy Markdown
Member

If you are calling Spack from the python API, you might have written something like this before #41529:

find = SpackCommand("find")
find('--format={name}', 'saxpy@1.0.0', '+rocm', 'amdgpu_target="gfx90a"')

But with the breaking change in #41529, you should write:

find = SpackCommand("find")
find('--format={name}', 'gromacs', '+rocm', 'amdgpu_target=gfx90a')

Note that we don't need quotes in Python strings, and that this is what would come in via argv if you typed a quoted variant on the CLI.

The error messages for strings like this are not great -- you get something like this:

==> No package matches the query: gromacs+rocm amdgpu_target="gfx90a"

Which doesn't indicate that the issue might be your quoting. This is because we were simply outputting the argv we got, instead of using spec.format() to output the error message. This PR fixes such errors to use spec.format() and to look like this:

==> No package matches the query: gromacs+rocm amdgpu_target='"gfx90a"'

So users should have an easier time understanding that Spack considers the variant value to contain quotes here.

  • update ConstraintAction to store parsed Specs
  • refactor commands to display formatted parsed Specs instead of raw input

If you are calling Spack from the python API, you might have written something like this
before #41529:

```
find = SpackCommand("find")
find('--format={name}', 'saxpy@1.0.0', '+rocm', 'amdgpu_target="gfx90a"')
```

But with the breaking change in #41529, you should write:

```
find = SpackCommand("find")
find('--format={name}', 'gromacs', '+rocm', 'amdgpu_target=gfx90a')
```

Note that we don't need quotes in Python strings, and that this is what would come in
via argv if you typed a quoted variant on the CLI.

The error messages for strings like this are not great -- you get something like this:

```
==> No package matches the query: gromacs+rocm amdgpu_target="gfx90a"
```

Which doesn't indicate that the issue might be your quoting. This is because we were
simply outputting the argv we got, instead of using spec.format() to output the error
message. This PR fixes such errors to use `spec.format()` and to look like this:

```
==> No package matches the query: gromacs+rocm amdgpu_target='"gfx90a"'
```

So users should have an easier time understanding that Spack considers the variant value
to contain quotes here.

- [x] update ConstraintAction to store parsed Specs
- [x] refactor commands to display formatted parsed Specs instead of raw input
@spackbot-app spackbot-app bot added commands core PR affects Spack core functionality labels Dec 21, 2023
@becker33 becker33 merged commit 0a5f2fc into develop Dec 21, 2023
@becker33 becker33 deleted the better-spec-query-errors branch December 21, 2023 17:06
RikkiButler20 pushed a commit to RikkiButler20/spack that referenced this pull request Jan 31, 2024
If you are calling Spack from the python API, you might have written something like this
before spack#41529:

```
find = SpackCommand("find")
find('--format={name}', 'saxpy@1.0.0', '+rocm', 'amdgpu_target="gfx90a"')
```

But with the breaking change in spack#41529, you should write:

```
find = SpackCommand("find")
find('--format={name}', 'gromacs', '+rocm', 'amdgpu_target=gfx90a')
```

Note that we don't need quotes in Python strings, and that this is what would come in
via argv if you typed a quoted variant on the CLI.

The error messages for strings like this are not great -- you get something like this:

```
==> No package matches the query: gromacs+rocm amdgpu_target="gfx90a"
```

Which doesn't indicate that the issue might be your quoting. This is because we were
simply outputting the argv we got, instead of using spec.format() to output the error
message. This PR fixes such errors to use `spec.format()` and to look like this:

```
==> No package matches the query: gromacs+rocm amdgpu_target='"gfx90a"'
```

So users should have an easier time understanding that Spack considers the variant value
to contain quotes here.

- [x] update ConstraintAction to store parsed Specs
- [x] refactor commands to display formatted parsed Specs instead of raw input
kwryankrattiger pushed a commit to kwryankrattiger/spack that referenced this pull request Jul 9, 2024
If you are calling Spack from the python API, you might have written something like this
before spack#41529:

```
find = SpackCommand("find")
find('--format={name}', 'saxpy@1.0.0', '+rocm', 'amdgpu_target="gfx90a"')
```

But with the breaking change in spack#41529, you should write:

```
find = SpackCommand("find")
find('--format={name}', 'gromacs', '+rocm', 'amdgpu_target=gfx90a')
```

Note that we don't need quotes in Python strings, and that this is what would come in
via argv if you typed a quoted variant on the CLI.

The error messages for strings like this are not great -- you get something like this:

```
==> No package matches the query: gromacs+rocm amdgpu_target="gfx90a"
```

Which doesn't indicate that the issue might be your quoting. This is because we were
simply outputting the argv we got, instead of using spec.format() to output the error
message. This PR fixes such errors to use `spec.format()` and to look like this:

```
==> No package matches the query: gromacs+rocm amdgpu_target='"gfx90a"'
```

So users should have an easier time understanding that Spack considers the variant value
to contain quotes here.

- [x] update ConstraintAction to store parsed Specs
- [x] refactor commands to display formatted parsed Specs instead of raw input
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands core PR affects Spack core functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants