psych: wrong line reported in 'did not find expected key while parsing a block mapping'
When parsing this yaml
key_one:
inner:
- value1
- value2
key_two:
inner:
- value1
- value2
the error message
Psych::SyntaxError: (/tmp/oops.yaml): did not find expected key while parsing a block mapping at line 1 column 1
contains the wrong line number. It should be reporting line 7 column 5.
About this issue
- Original URL
- State: open
- Created 10 years ago
- Reactions: 102
- Comments: 64
Commits related to this issue
- script key in .yml had space before it trying out solution suggested in https://github.com/ruby/psych/issues/190#issuecomment-162658663 — committed to aredfox/Fools-Paradice by aredfox 7 years ago
- Fix .yaml, see https://github.com/ruby/psych/issues/190 — committed to vrhk/vrhk.github.io by deleted user 7 years ago
- Fix .yaml, see https://github.com/ruby/psych/issues/190 — committed to vrhk/vrhk.github.io by deleted user 7 years ago
- Fix error in yml by using http://www.yamllint.com/ and https://github.com/ruby/psych/issues/190 — committed to gap-packages/SimplicialSurfaces by markusbaumeister 5 years ago
- fixing the missing spaces Detailed explanation on the issues with the structure can be found here: https://github.com/ruby/psych/issues/190 — committed to TestEdWorkshop/2020 by andras-marki 5 years ago
To anyone stumbling through the internet that finds this issue for related reasons: Somewhere in your YAML you have extra spaces (or not enough spaces) before a key value. Thank you all for helping me solve this on a completely different project!
Edit on December 10, 2019: A great YAML linter may help here: https://jsonformatter.org/yaml-formatter.
+1, got bitten by this issue today. Very annoying when the syntax error occured nearly 1500 lines into the file!
For anyone who is looking for this stupid error, I fix error by removing " ’ " character.
(WHITESPACE AS SYNTAX IS THE DUMBEST THING EVER), thank you
+1 on the empty space in the yml file. Copy/paste error.
so it was a bad copy for me.
In vim I did a search of
^\(\s\s\)\+to find all instances of good spacing and was able to find my bugSave me a lot of time. And here is a yamllint tool. http://www.yamllint.com/
Here’s command-line yamllint. It gives the correct line number.
https://github.com/adrienverge/yamllint
When this happens to me, I use this tool it tells you the line that is wrong:
https://yamlchecker.com/
@ORESoftware that’s the whole point of using YAML. Use JSON instead.
@pooja-mane Can you try something:
Had the same issue on Windows 10 today. I used https://yamlchecker.com/ as recommended by @WaKeMaTTa
Resolution: No double quotes needed for Windows directory.
For me the line number was incorrect when I had unescaped double quotes inside a value…
@elcortez thank you. I got my mistake in code. create_list: “Create a List” message: “Save Profiles” as I was using massage key as create_list.message which is wrong. as when it searches for for create_list it got a label “Create a List” it wont go to search for message key. I changed my code as create_list: message: “Save Profiles”
Thank you @mahemoff, you just saved me a world of pain!
@illepic Thank you so much! I was missing an extra space.
I guess it’s winding back to the start of the structure it’s trying to parse, rather than flagging the error then and there…
Wow. Error was fixed when I trimmed the lines and got rid of spaces, wtf
Thanks @illepic!
I ran into the same problem and decided to open an issue https://github.com/travis-ci/travis-yaml/issues/128
Had the same issue, but instead of wrong whitespaces I got comments inside a single command like the following:
The
travis lintreported error on line 2, column 1 or on line 1, column 1 during my experiments. While error was on some 23 line 😕 I’m glad I solved this puzzle 😃I saw this issue (“line 1, column 1”) do to a comma at the end of the line after converting json by hand.
E.g.
Thanks @illepic!
Super glad I found this issue. Probably saved my an hour of hair pulling. In my case, it seems to be reporting the correct column number, but still reports line 1 incorrectly.