Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong line reported in 'did not find expected key while parsing a block mapping' #190

Open
djellemah opened this issue May 19, 2014 · 64 comments

Comments

@djellemah
Copy link

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.

@anicholson
Copy link

+1, got bitten by this issue today. Very annoying when the syntax error occured nearly 1500 lines into the file!

@anicholson
Copy link

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...

@happycollision
Copy link

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.

@illepic
Copy link

illepic commented Dec 7, 2015

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.

@DaveCollinsJr
Copy link

+1 on the empty space in the yml file. Copy/paste error.

@felipecrv
Copy link

@illepic Thank you so much! I was missing an extra space.

@rohstar
Copy link

rohstar commented Mar 2, 2016

thanks @illepic!

@cleverington
Copy link

Thanks @illepic!

@Gimcrack
Copy link

Found my syntax error. Thanks! @illepic

@BatuhanW
Copy link

For anyone who is looking for this stupid error, I fix error by removing " ' " character.

@sanguis
Copy link

sanguis commented Jun 21, 2016

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 bug

@dangan249
Copy link

+1

@aurawindsurfing
Copy link

209:11 should have beed 209:09 ... cheers for pointing that out!

@ryanooi
Copy link

ryanooi commented Sep 13, 2016

Please check spacing. i got the same error because additional spacing.

@pooja-mane
Copy link

Hi I also got this error as
"did not find expected key while parsing a block mapping at line 3 column 5"
My code is as follow
create_list: "Create a List"
message: "Save Profiles"
but when I place a message key in another key it works fine.
plz tell me if any one knows solution...
I have checked spacing also, as there is no extra spacing in line.
Thank you...

@elcortez
Copy link

elcortez commented Oct 3, 2016

@pooja-mane Can you try something:

  • delete the lines where the problem seems to happens
  • check that you can launch your server after deleting (if so, you have spotted where are the 'wrong' lines)
  • rewrite them by hand
  • be careful with "'" and '"' : use " mostly if possible
  • I had this issue after bulk changing all my " to '; and then there was a "If you didn"t request" so you see my mistake was very small indeed ^^

@pooja-mane
Copy link

@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"

@einverne
Copy link

Save me a lot of time. And here is a yamllint tool. http://www.yamllint.com/

@joney000
Copy link

+1

@mahemoff
Copy link

Here's command-line yamllint. It gives the correct line number.

https://github.com/adrienverge/yamllint

@ORESoftware
Copy link

ORESoftware commented Nov 28, 2016

(WHITESPACE AS SYNTAX IS THE DUMBEST THING EVER), thank you

@felipecrv
Copy link

@ORESoftware that's the whole point of using YAML. Use JSON instead.

@andydempster
Copy link

andydempster commented Jan 23, 2017

Here's command-line yamllint. It gives the correct line number.
https://github.com/adrienverge/yamllint

Thank you @mahemoff, you just saved me a world of pain!

aredfox added a commit to aredfox/Fools-Paradice that referenced this issue Feb 3, 2017
@vfonic
Copy link

vfonic commented Mar 31, 2017

Ended up here after missing a closing ' sign.

Let's assume paths: is at line 1.

The error message was:
did not find expected key while parsing a block mapping at line 5 column 3 (Psych::SyntaxError)

While the actual error is at line 20.

 1. paths:
 2.   # customer:
 3.   #   path: /news/entertainment-arts-27221191
 4.   # before_capture: 'javascript/interact--casper.js' # (optional) JavaScript file to execute before taking the screenshot of this path.
 5.   customers_login:                '/account/login'
 6.   customers_register:             '/account/register'
 7.   404:                            '/wraith_testing'
 8.   article_konfigurator:           '/blogs/blog/alte-brillen-neu-verglasen'
 9.   article:                        '/blogs/blog/warum-werden-brillenglaeser-entspiegelt'
10.   article_lexikon:                        '/blogs/lexikon/basis' # blog lexikon article
11.   blog_lexikon:                   '/blogs/lexikon' # blog index
12.   blog_lexikon_tag:                   '/blogs/lexikon/tagged/b' # blog lexikon tag
13.   blog:                           '/blogs/blog'
14.   cart:                           '/cart'
15.   index:                          '/'
16.   page_about_us:                  '/pages/uber-topglas'
17.   page_composer_einstarkenglaser: '/pages/einstarkenglaser'
18.   page_composer_gleitsichtglaser: '/pages/gleitsichtglaeser'
19.   page_composer_koln:             '/pages/optiker-koeln'
20.   page_consulting:                '/pages/unsere-brillenglaser-im-detail # HERE'S THE ERROR
21.   page_contact:                   '/pages/kontakt'
22.   page_faq:                       '/pages/haeufige-fragen'
23.   page_functioniert:              '/pages/so-funktionierts'
24.   page_konfigurator:              '/pages/brillenglaeser-online-auswaehlen'
25.   page:                           '/pages/lieferzeiten'
26.   search:                         '/search'
27.   search:                         '/search?type=article,page&q=sehstarke'

@juanmirocks
Copy link

Do not write colons within strings as in:

- printf 'commit:'`

@goalaleo
Copy link

goalaleo commented May 23, 2017

For me the line number was incorrect when I had unescaped double quotes inside a value...

@farfromunique
Copy link

Copy/pasting code from the internet can have WEIRD results. I had to re-write an entire file to fix this issue; my spaces and quotes were right, but there were invisible whitespace characters hidden... somewhere.

@emfluenceindia
Copy link

This vagrant error reporting must be looked into! For me reported line number was 74, while it was 84 actually. For beginners like me its a nightmare to understand what's went wrong! It was no copy/paste for me... I forgot to enable the key called plugins while I have user-switching added under it! :) Glad that I could find it out quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests