Skip to content

codegen all languages: issue nicer error message in the event of invalid YAML #849

Open
@mr-c

Description

@mr-c

Example from cwl-utils:

env3.11) michael@mrc-tux:~/cwl-utils$ python3 dump_test.py 
Traceback (most recent call last):
  File "/home/michael/cwl-utils/dump_test.py", line 12, in <module>
    cwl_obj = load_document_by_uri(cwl_file)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/michael/cwl-utils/cwl_utils/parser/__init__.py", line 183, in load_document_by_uri
    return load_document_by_string(doc, real_uri, loadingOptions, id_, load_all)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/michael/cwl-utils/cwl_utils/parser/__init__.py", line 210, in load_document_by_string
    result = yaml.load(string)
             ^^^^^^^^^^^^^^^^^
  File "/home/michael/cwl-utils/env3.11/lib/python3.11/site-packages/ruamel/yaml/main.py", line 426, in load
    return constructor.get_single_data()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/michael/cwl-utils/env3.11/lib/python3.11/site-packages/ruamel/yaml/constructor.py", line 111, in get_single_data
    node = self.composer.get_single_node()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/michael/cwl-utils/env3.11/lib/python3.11/site-packages/ruamel/yaml/composer.py", line 64, in get_single_node
    self.parser.get_event()
  File "/home/michael/cwl-utils/env3.11/lib/python3.11/site-packages/ruamel/yaml/parser.py", line 158, in get_event
    self.current_event = self.state()
                         ^^^^^^^^^^^^
  File "/home/michael/cwl-utils/env3.11/lib/python3.11/site-packages/ruamel/yaml/parser.py", line 173, in parse_stream_start
    token = self.scanner.get_token()
            ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/michael/cwl-utils/env3.11/lib/python3.11/site-packages/ruamel/yaml/scanner.py", line 1763, in get_token
    self._gather_comments()
  File "/home/michael/cwl-utils/env3.11/lib/python3.11/site-packages/ruamel/yaml/scanner.py", line 1757, in _gather_comments
    self.fetch_more_tokens()
  File "/home/michael/cwl-utils/env3.11/lib/python3.11/site-packages/ruamel/yaml/scanner.py", line 292, in fetch_more_tokens
    return self.fetch_literal()
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/michael/cwl-utils/env3.11/lib/python3.11/site-packages/ruamel/yaml/scanner.py", line 675, in fetch_literal
    self.fetch_block_scalar(style='|')
  File "/home/michael/cwl-utils/env3.11/lib/python3.11/site-packages/ruamel/yaml/scanner.py", line 686, in fetch_block_scalar
    self.tokens.append(self.scan_block_scalar(style))
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/michael/cwl-utils/env3.11/lib/python3.11/site-packages/ruamel/yaml/scanner.py", line 1919, in scan_block_scalar
    return Scanner.scan_block_scalar(self, style, rt=rt)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/michael/cwl-utils/env3.11/lib/python3.11/site-packages/ruamel/yaml/scanner.py", line 1104, in scan_block_scalar
    chomping, increment = self.scan_block_scalar_indicators(start_mark)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/michael/cwl-utils/env3.11/lib/python3.11/site-packages/ruamel/yaml/scanner.py", line 1256, in scan_block_scalar_indicators
    raise ScannerError(
ruamel.yaml.scanner.ScannerError: while scanning a block scalar
  in "<unicode string>", line 1, column 1:
    |Linux Build Status| |Code cover ... 
    ^ (line: 1)
expected chomping or indentation indicators, but found 'L'
  in "<unicode string>", line 1, column 2:
    |Linux Build Status| |Code covera ... 
     ^ (line: 1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions