linter error
Input
Given this workflow.yml
name: Lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Advanded Linting Devices Inc.
run: |
sudo apt-get update
sudo apt-get install -y advanced-linting-device
- name: Set locale
run: |
export LC_ALL=C.UTF-8
- name: COMMON → Lint line endings (show files with DOS LE and EOL errors)
run: |
find -name '*.*' -print0 | xargs -0 dos2unix -ice
Expected Output
- Identation error on line 22
Actual Output
-
could not parse as YAML: yaml: line 16: did not find expected key [syntax-check]
Analysis
The wrong indention in the last step causes the linter to assume an invalid could not parse as YAML: yaml: line 16: did not find expected key [syntax-check] error.
References
For fellow Googlers:
THis cryptic error also happens when using brackets: [foo] which actionlint doesn't like at all (even though GA works)
@jakoch As a comparison, the pyyaml-based YAML parser throws two errors on your YAML example (link):
ERROR:
while parsing a block mapping
in "<unicode string>", line 17, column 9:
- name: Set locale
^
expected <block end>, but found '-'
in "<unicode string>", line 21, column 9:
- name: COMMON → Lint line endin ...
^
@riva-infinex Could you provide a concrete example?
@muzimuzhi cryptic error https://rhysd.github.io/actionlint/#eJxTVshIzcnJV+TiykvMTbVSiHbLz49VSEos4gIAZuYHww==
@riva-infinex name: [Foo] bar is an invalid YAML. https://yaml-online-parser.appspot.com/?yaml=name%3A+%5BFoo%5D+bar&type=json
[...] represents an inline sequence (technically called "flow sequence"), which cannot be followed by a string on the same line. To specify a string which starts with [, quoting the whole string is a common workaround.
# single-quoted
name: '[Foo] bar'
# double-quoted
name2: "[Foo] bar"
https://yaml-online-parser.appspot.com/?yaml=name%3A+%27%5BFoo%5D+bar%27%0Aname2%3A+%22%5BFoo%5D+bar%22&type=json
Update: If the GitHub Actions accepts such YAML snippet, then it's YAML parser might not be strict enough.
@muzimuzhi I completely agree! My comment is about the cryptic error message:
- (playground above) it complains about line 2 when the error is on line 3
- the message "did no find expected key" doesn't mention anything about brackets or flow sequences
@riva-infinex The cryptic error message "did not find expected key" was provided by the YAML parser gopkg.in/yaml.v3 v3.0.1 used by actionlint, so it's an upstream issue. See reproduction steps at the end.
https://github.com/rhysd/actionlint/blob/2ab3a12c7848f6c15faca9a92612ef4261d0e370/go.mod#L16
The shifted line number seems to be caused by actionlint.
Reproduction of "did not find expected key" error message:
- open https://pkg.go.dev/gopkg.in/[email protected]#example-Unmarshal-Embedded
- Edit the embedded example
var data = ` -a: a string x from struct A +a: [Foo] bar b: a string x from struct B ` - Click the lower-right "Run" button, wait, and get the error message
2009/11/10 23:00:00 cannot unmarshal data: yaml: line 1: did not find expected key
Unfortunately, the source repo of the Go package gopkg.in/yaml has been archived on Apr 2, 2025. See https://github.com/go-yaml/yaml.
Thank you for taking the time to analyze this. I just checked the dependencies of yq and noticed it includes goccy/go-yaml. This might serve as a potential replacement package.