Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

How to fix "mapping values are not allowed in this context " error in yaml file?

Writer Matthew Harrington

I've browsed similar questions and believe i've applied all that i've been able to glean from answers.

I have a .yml file where as far as I can tell each element is formatted identically. And yet according to YamlLint.com

(<unknown>): mapping values are not allowed in this context at line 119 column 16

In this case, line 119 is the line containing the second instance the word "transitions" below. That I can tell each element is formatted identically. Am I missing something here?

 landingPage: include: false transitions: - condition:location nextState:location location: include:false transitions: - condition:excluded nextState:excluded excluded: include:false transitions: - condition:excluded nextState: excluded - condition:age nextState:age

8 Answers

You cannot have a multiline plain scalar, such as your include:false transitions be the key to a mapping, that is why you get the mapping values not allowed in this context error.

Either you forgot that you have to have a space after the value indicator (:), and you meant to do:

 include: false transitions:

or you need to quote your multi-line scalar:

 'include:false transitions':

or you need to put that plain scalar on one line:

 include:false transitions:

please note that some libraries do not allow value indicators in a plain scalar at all, even if they are not followed by space

we need to use space before ":" Then it will excecute check the yaml script in below

I fixed this for myself by simply realizing I had indented a line too far, and un-indenting it.

1

For me the problem was a unicode '-' from a cut and paste. Visualy it looked OK, but the character was 'EN DASH' (U+2013) instead of 'HYPHEN MINUS' (U+002D)

There are couple of issues in the yaml file, with yaml files it gets messy, fortunately it can be identified easily with tools like yaml lint

Install it

npm install -g yaml-lint

Here is how you can validate

E:\githubRepos\prometheus-sql-exporter-usage\etc>yamllint prometheus.yaml
√ YAML Lint successful.
1

In mine case it was the space after the : in a value:

query-url: blabla

To fix:

query-url: 

Or:

query-url: " blabla"

If you are using powershell and have copied the cat command, it won't work properly (I'm guessing it is encoding the content in some way). Instead of using "$(cat file.yaml)" you should use $(Get-Content file.yaml -Raw) without the quotes.

Really annoying!

In my case if was some odd disappearing of the initial formatting of the initial chart that was copied in Intellij Idea. It was possible to gfigure out with text-compare tool only:

enter image description here

So, when you do your copy and paste in your IDE, please double check is what you have copied is exactly what you paste, aren't some additional spaces were added.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy