Common causes
- An unquoted value containing ': ', such as title: Error: file missing
- A child key indented under a key that already has a scalar value
- A missing space after the colon on the line above (key:value), which turns it into a plain string
- A list item written without its - dash, or a dash with wrong indentation
- A Windows path or time string with a colon and space inside an unquoted value
- Copying YAML from a web page that changed spaces or indentation
How to fix it
- Go to the reported line and column. The column usually points at the colon the parser rejected. Look at that line and the one directly above it, since the real mistake is often on the previous line.
- Quote values that contain colons. Change title: Error: file missing to title: "Error: file missing" or use single quotes. Inside double quotes escape \ and " ; inside single quotes double a single quote ('').
- Check the indentation. A key with a value on the same line cannot also have indented child keys. Either move the value into a child key or remove the extra indentation, and use spaces, never tabs.
- Add missing spaces and dashes. Make sure every key has a space after the colon (key: value) and every list item starts with '- '. For multi-line text use a block scalar with | or >.
- Validate before deploying. Run the file through a YAML parser, for example python3 -c "import yaml,sys; yaml.safe_load(open(sys.argv[1]))" config.yml, or the linter for your tool (docker compose config, kubectl apply --dry-run=client).
YAML
# wrong: unquoted ': ' inside the value
message: Error: file missing
# right
message: "Error: file missing"
# wrong: key has a value and children
server: web1
port: 8080
# right
server:
name: web1
port: 8080 How to stop it happening again
- Quote any string value that contains ': ' or starts with special characters like *, &, ! or @
- Configure your editor to insert spaces for tabs and show indentation guides in YAML files
- Run a YAML linter such as yamllint in CI
- Use block scalars (| or >) for long or multi-line text