Menu

#391 ScannerError: while scanning a plain scalar found unexpected ':'

closed
nobody
None
trivial
bug
2021-08-17
2021-08-17
No

I use check-yaml hook from pre-commit-hooks to validate YAML files in project.
The pnpm generate such sort of construction (in pnpm-lock.yaml):

github.com/account_name/package_name/md5:
  resolution: {tarball: https://codeload.github.com/account_name/package_name/tar.gz/md5}

And on this file the check-yaml raises validation error:

while scanning a plain scalar
  in "test.yml", line 2, column 25
found unexpected ':'
  in "test.yml", line 2, column 30

Same in python (ruamel.yaml==0.17.10):

>>> import ruamel.yaml
>>> yaml = ruamel.yaml.YAML(typ='safe')
 >>> yaml.load("""
... github.com/account_name/package_name/md5:
...   resolution: {tarball: https://codeload.github.com/account_name/package_name/tar.gz/md5}
... """)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".direnv/python-3.8.5/lib/python3.8/site-packages/ruamel/yaml/main.py", line 434, in load
    return constructor.get_single_data()
  File ".direnv/python-3.8.5/lib/python3.8/site-packages/ruamel/yaml/constructor.py", line 120, in get_single_data
    node = self.composer.get_single_node()
  File "_ruamel_yaml.pyx", line 706, in _ruamel_yaml.CParser.get_single_node
  File "_ruamel_yaml.pyx", line 724, in _ruamel_yaml.CParser._compose_document
  File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
  File "_ruamel_yaml.pyx", line 889, in _ruamel_yaml.CParser._compose_mapping_node
  File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
  File "_ruamel_yaml.pyx", line 889, in _ruamel_yaml.CParser._compose_mapping_node
  File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
  File "_ruamel_yaml.pyx", line 889, in _ruamel_yaml.CParser._compose_mapping_node
  File "_ruamel_yaml.pyx", line 731, in _ruamel_yaml.CParser._compose_node
  File "_ruamel_yaml.pyx", line 904, in _ruamel_yaml.CParser._parse_next_event
ruamel.yaml.scanner.ScannerError: while scanning a plain scalar
  in "<unicode string>", line 3, column 25
found unexpected ':'
  in "<unicode string>", line 3, column 30

Discussion

  • Anthon van der Neut

    • status: open --> closed
    • priority: major --> trivial
     
  • Anthon van der Neut

    You shouldn't load with typ='safe', that way ruamel.yaml uses the C based loader and that has problems inherited from PyYAML in that is does see a string with a value indicator (:) in the middle as a key value pair even if that indicator is not followed by a colon. Instantiate using YAML(typ='safe', pure=True) then you get the Python based loader that properly checks if the value indicator is followed by a space. (Aternatively quote the URL)

     

Log in to post a comment.

MongoDB Logo MongoDB