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

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

Open
mr-c opened this issue Jul 18, 2024 · 3 comments
Open

Comments

@mr-c
Copy link
Member

mr-c commented Jul 18, 2024

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)

@tom-tan
Copy link
Member

tom-tan commented Jul 19, 2024

Is this an issue to improve the error messages by the code generator in schema_salad or an issue to improve the messages by code generated parsers?

@mr-c
Copy link
Member Author

mr-c commented Jul 19, 2024

an issue to improve the messages by code generated parsers?

This one

@mr-c
Copy link
Member Author

mr-c commented Jul 19, 2024

So the Python generated code should catch ruamel.yaml.scanner.ScannerError when calling ruamel.yaml functions and report it without the stacktrace; probably similar needed for the other languages

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

No branches or pull requests

2 participants