Could not parse YAML configuration file [S-6602]

This error occurs when Stack is unable to parse a YAML configuration file, which could be a project-level stack.yaml file or a global config.yaml file. The error covers the following situations:

The expected file formats are described in the Stack documentation.

Examples

Stack does not accept empty YAML files

When run with an empty YAML file, Stack fails to parse it. For example, stack --stack-yaml empty.yaml build results in the error:

Error: [S-6602]
       Stack could not load and parse /PATH/TO/empty.yaml as a YAML
       configuraton file.
       
       While loading and parsing, Stack encountered the following exception:
       
       Aeson exception:
       Error in $: parsing ProjectAndConfigMonoid failed, expected Object, but encountered Null
       
       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/.

This error in a project-level stack.yaml file can be fixed by specifying a resolver, which is the minimal stack.yaml configuration.

empty.yaml
Before
After
resolver: lts-19.17
Not a YAML file

This stack.yaml file is not syntactically valid YAML. The error that results from stack --stack-yaml not.yaml build is:

Error: [S-6602]
       Stack could not load and parse /PATH/TO/not.yaml as a YAML configuraton file.

       While loading and parsing, Stack encountered the following exception:

       YAML parse exception at line 0, column 0,
       while parsing a block node:
       did not find expected node content

       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/.
not.yaml
Before
]
After
resolver: lts-19.17