Expected block end YAML error - yaml

When pasting this YAML file into an online yaml parser, I got an expected block end error:
ADDATTEMPTING: 'Tentative d ajout '
ATTEMPTINGTOGIVE: 'Tenter de donner '
ATTEMPTINGTOSET1: 'Tentative de définition '
ATTEMPTINGTOSET2: ' avec '
ALREADYEXISTS: 'Erreur. Package existe déjà’
CANCEL1: 'Annulation...'
(...)
Error
ERROR:
while parsing a block mapping
in "<unicode string>", line 1, column 1:
ADDATTEMPTING: 'Tentative d ajout '
^
expected <block end>, but found '<scalar>'
in "<unicode string>", line 6, column 11:
CANCEL1: 'Annulation...'
^

The line starting ALREADYEXISTS uses ’ as the closing quote, it should be using '. The open quote on the next line (where the error is reported) is seen as the closing quote, and this mix up is causing the error.

This error also occurs if you use four-space instead of two-space indentation.
e.g., the following would throw the error:
fields:
- metadata: {}
name: colName
nullable: true
whereas changing indentation to two-spaces would fix it:
fields:
- metadata: {}
name: colName
nullable: true

I would like to make this answer for meaningful, so the same kind of
erroneous user can enjoy without feel any hassle.
Actually, i was getting the same error but for the different reason, in my case I didn't used any kind of quoted, still getting the same error like expected <block end>, but found BlockMappingStart.
I have solved it by fixing, the Alignment issue inside the same .yml file.
If we don't manage the proper 'tab-space(Keyboard key)' for
maintaining successor or ancestor then we have to phase such kind of
things.
Now i am doing well.

With YAML, remember that it is all about the spaces used to define configuration through the hierarchical structures (indents). Many problems encountered whilst parsing YAML documents simply stems from extra spaces (or not enough spaces) before a key value somewhere in the given YAML file.

YAML follows indentation structure very strictly. Even one space/tab can cause above issue. In my case it was just once space at the start.
So make sure no extra spaces/tabs are introduced while updating YAML file

I got same issue and found that there is space in next line which combine with content of yml. For solution i just remove that space. Thanks

In my case, the error occured when I tried to pass a variable which was looking like a bytes-object (b"xxxx") but was actually a string.
You can convert the string to a real bytes object like this:
foo.strip('b"').replace("\\n", "\n").encode()

Related

Yaml Syntax - can not read a block mapping entry; a multiline key may not be an implicit key

I have a .yaml file like this:
title: 'We'll do cool stuff'
draft: true
However, I get the following error:
Error parsing YAML: YAMLException: can not read a block mapping entry;
a multiline key may not be an implicit key at line 2, column 6:
draft: true
^
How can I fix it?
Note: this setup seems different than the other questions where this same error was raised, including the following posts:
Error parsing YAML
Getting following error on serverless.yaml
yaml syntax issues?
You can use a site like YAML Formatter to format and validate your yaml:
In this case, the error message and location is a bit of red-herring.
The error is actually caused by a string that was accidentally terminated because of an unescaped quote symbol within the string. A hint for this is the syntax highlighting of 'We'll do cool stuff'.
To fix, in this case, you can just skip wrapping the string quotes and rewrite like this:
title: We'll do cool stuff
draft: true
Further Reading
Do I need quotes for strings in YAML?
How to escape double and single quotes in YAML
title: "We'll do cool stuff"
draft: true
I have got the exact same issue, The problem with it is, we are using a single quote' in between the string and also wrapping the string with a single quote.
I resolved it by wrapping the string with a double quote.
You can also trace the issue more by reading this

YAML, linting - syntax error - unknown escape character '

Hello Developer Community!
I would like to ask for some help about the following, I have the following YAML data:
---
# yamllint disable rule:indentation rule:empty-lines
config_nsapp_cs_policy:
nsapp_cs_policy:
- policyname: "url_app_preprd"
rule: "URL == \'/string/*\'"
When trying to run YAML lint against the YAML file, I get the following error:
7:69 error syntax error: found unknown escape character "'" (syntax)
Is it possible to define an exception rule for this specific linting rule (ignoring the problematic content in 'single quote')? I was thinking about completely disable / ignore YAML linting for the file as a whole, but it would not be the best approach. I do not know which YAML linting rule the single quote is matching. The single quote is expected in the line.
Thank You very much in advance!
This is not a linter error, this is a parser error. Your input is invalid YAML because an escape sequence \' is not defined in YAML.
If the scalar content should simply contain single quotes, do
rule: "URL == '/string/*'"
If the scalar content should also contain the backslashes, do
rule: "URL == \\'/string/*\\'"
You can use a block scalar instead to avoid escaping the backslash:
rule: >-
URL == \'/string/*\'

Go compiler: error line number is incorrect giving 1048575 i.e. 0xFFFFF when problem is further on in the file

I am testing code-generation functionality and deliberately creating very large .go source files.
However I see errors with go compiler at line 1048575 (which is 0xFFFFF) such as:
generated.go:1048575:75: invalid character U+0040 '#'
generated.go:1048575:76: const declaration cannot have type without expression
generated.go:1048575:88: syntax error: unexpected E_Blah_Blah, expecting semicolon or newline or )
Is this a known limitation?
EDIT-1: Commenters asked for more info on content of generated file; further tests show when I deliberately introduce a new error at line 1048573 or 1048574 it gets reported as I'd expect, but if I introduced one at 1048575 or higher line number the file I always get the error reported at 1048575.
EDIT-2: I realise now the original issue invalid character U+0040 '#' was indeed a bug in my generated file but it was further down that line number the compiler tells me.
EDIT-3: So I guess the question should really have been:
is there a way to have the go-compiler give the correct line number for a problem if error further down than line 0xFFFFF?
Is this a known limitation ?
No.
The root cause was:
https://github.com/golang/go/issues/36850
i.e. Compiler bug: error line number is capped at 0xFFFFF
as per comment from #icza

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

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
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
I fixed this for myself by simply realizing I had indented a line too far, and un-indenting it.
we need to use space before ":"
Then it will excecute
check the yaml script in below
http://www.yamllint.com/
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.
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)
In mine case it was the space after the : in a value:
query-url: https://blabla.com/blabla?label=blabla: blabla
To fix:
query-url: https://blabla.com/blabla?label=blabla:%20blabla
Or:
query-url: "https://blabla.com/blabla?label=blabla: 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:
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.

Here document gives EOF error in Ruby IO

The following code give two errors which I am not able to resolve. Any help would be appreciated:
random.rb:10: can't find string "TEMPLATE" anywhere before EOF
random.rb:3: syntax error, unexpected end-of-input
Code:
id = 2
File.open("#{id}.json","w") do |file|
file.write <<TEMPLATE
{
"submitter":"#{hash["submitter"]}",
"quote":"#{hash["quote"]}",
"attribution":"#{hash["attribution"]}"
}
TEMPLATE
end
From the documentation (emphasis mine):
The heredoc starts on the line following <<HEREDOC and ends with the next line that starts with HEREDOC
Your code doesn't contain a line starting with TEMPLATE. If your text editor (or IDE) supports regular expressions in searches, try ^TEMPLATE.
You can either remove the spaces or if you want to keep them, change <<TEMPLATE into <<-TEMPLATE. The addition of - instructs the Ruby parser to search for an (possibly) intended TEMPLATE like you have in your code.

Resources