commercialhaskell / stack

The Haskell Tool Stack
http://haskellstack.org
BSD 3-Clause "New" or "Revised" License
3.95k stars 842 forks source link

stack config set makes stack.yaml invalid (Error: [S-6602]) #6554

Closed dunric closed 2 months ago

dunric commented 2 months ago

General summary/comments (optional)

Updating configuration of resolver with stack config set renders stack.yaml invalid.

Steps to reproduce

  1. create a new project with stack new myproj, for example
  2. enter in project's root directory with cd myproj
  3. update resolver option with stack config set resolver nightly
  4. resolver.url key is updated improperly
--- stack.yaml.orig      2024-04-16 21:05:44.636267302 +0200
+++ stack.yaml      2024-04-16 21:15:26.472945061 +0200
@@ -17,7 +17,7 @@
 #
 # resolver: ./custom-snapshot.yaml
 # resolver: https://example.com/snapshots/2023-01-01.yaml
-resolver:
+resolver:nightly-2024-04-14
   url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/17.yaml

 # User packages to be built.

Expected

Resolver entry should contain

resolver: nightly-2024-04-14

and url subkey should be removed or commented out

#    url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/17.yaml`

Actual

resolver:nightly-2024-04-14
   url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/17.yaml

Attempts to invoke stack commands like build or run fail with

stack build --verbose
Version 2.15.5, Git revision 5649cc6b2522f51f0fc5543154b0fff868f9af31 x86_64 hpack-0.36.0
2024-04-16 21:24:30.808185: [debug] Checking for project config at: /home/dunric/Projects/Haskell/myproj/stack.yaml
2024-04-16 21:24:30.808481: [debug] Loading project config file stack.yaml
2024-04-16 21:24:30.808970: [debug] Checking for project config at: /home/dunric/Projects/Haskell/myproj/stack.yaml
2024-04-16 21:24:30.809038: [debug] Loading project config file stack.yaml
2024-04-16 21:24:30.809163: [error] 
Error: [S-6602]
       Stack could not load and parse /home/dunric/Projects/Haskell/myproj/stack.yaml
       as a YAML configuraton file.

       While loading and parsing, Stack encountered the following error:

       YAML parse exception at line 20, column 5:
       mapping values are not allowed in this context

       For help about the content of Stack's YAML configuration files, see (for the
       most recent release of Stack)
       http://docs.haskellstack.org/en/stable/yaml_configuration/.

Stack version

stack --version
Version 2.15.5, Git revision 92439b8a94e82e9128a5bc5cd0b21b43e99ffc85 x86_64 hpack-0.36.0

Method of installation

Via GHCup

Platform

x86_64 GNU/Linux

mpilgrem commented 2 months ago

@dunric, thanks for reporting. This is both a limitation of the current feature and a bug.

The limitation is that the config set commands only handle existing keys of the form key: value ... (where ..., if it exists, is assumed to be a comment) on a single line.

The bug is that (a) the parser of a single line was intended to fail (with a warning) if it did not have that form; and (b) the limitation of the feature is not documented online.

I've raised pull requests to fix the bug.

The barrier to a more capable feature is the challenge of modifying the substantive content of a YAML file (read by code) while preserving its form (including comments) (read by people).