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

User unfriendly error message when datetime is invalid #40

Open
midnightercz opened this issue Oct 12, 2021 · 4 comments
Open

User unfriendly error message when datetime is invalid #40

midnightercz opened this issue Oct 12, 2021 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@midnightercz
Copy link

When there's invalid date string in csv files, operator-manifest fails with ValueError raised by yaml module:
ValueError: year 0 is out of range
That is not very helpful error message as user cannot see where is the actual problem. If there's required format for some fields in csv files, those should be validated against some schema before yaml module tries to parse them
Here's snippet with invalid data:

createdAt: 0000-00-00T00:00:00Z                                                                 
@MartinBasti
Copy link
Contributor

Can you please provide traceback, where exactly this error is from?

@midnightercz
Copy link
Author

  File "/opt/iib-worker/virtualenv/lib/python3.6/site-packages/operator_manifest/operator.py", line 565, in from_directory
    operator_csvs = list(cls._get_csvs(yaml_files, **kwargs))
  File "/opt/iib-worker/virtualenv/lib/python3.6/site-packages/operator_manifest/operator.py", line 579, in _get_csvs
    yield OperatorCSV.from_file(f, **kwargs)
  File "/opt/iib-worker/virtualenv/lib/python3.6/site-packages/operator_manifest/operator.py", line 327, in from_file
    data = yaml.load(f)
  File "/opt/iib-worker/virtualenv/lib/python3.6/site-packages/ruamel/yaml/main.py", line 343, in load
    return constructor.get_single_data()
  File "/opt/iib-worker/virtualenv/lib/python3.6/site-packages/ruamel/yaml/constructor.py", line 113, in get_single_data
    return self.construct_document(node)
  File "/opt/iib-worker/virtualenv/lib/python3.6/site-packages/ruamel/yaml/constructor.py", line 123, in construct_document
    for _dummy in generator:
  File "/opt/iib-worker/virtualenv/lib/python3.6/site-packages/ruamel/yaml/constructor.py", line 1563, in construct_yaml_map
    self.construct_mapping(node, data, deep=True)
  File "/opt/iib-worker/virtualenv/lib/python3.6/site-packages/ruamel/yaml/constructor.py", line 1469, in construct_mapping
    value = self.construct_object(value_node, deep=deep)
  File "/opt/iib-worker/virtualenv/lib/python3.6/site-packages/ruamel/yaml/constructor.py", line 146, in construct_object
    data = self.construct_non_recursive_object(node)
  File "/opt/iib-worker/virtualenv/lib/python3.6/site-packages/ruamel/yaml/constructor.py", line 188, in construct_non_recursive_object
    for _dummy in generator:
  File "/opt/iib-worker/virtualenv/lib/python3.6/site-packages/ruamel/yaml/constructor.py", line 1563, in construct_yaml_map
    self.construct_mapping(node, data, deep=True)
  File "/opt/iib-worker/virtualenv/lib/python3.6/site-packages/ruamel/yaml/constructor.py", line 1469, in construct_mapping
    value = self.construct_object(value_node, deep=deep)
  File "/opt/iib-worker/virtualenv/lib/python3.6/site-packages/ruamel/yaml/constructor.py", line 146, in construct_object
    data = self.construct_non_recursive_object(node)
  File "/opt/iib-worker/virtualenv/lib/python3.6/site-packages/ruamel/yaml/constructor.py", line 188, in construct_non_recursive_object
    for _dummy in generator:
  File "/opt/iib-worker/virtualenv/lib/python3.6/site-packages/ruamel/yaml/constructor.py", line 1563, in construct_yaml_map
    self.construct_mapping(node, data, deep=True)
  File "/opt/iib-worker/virtualenv/lib/python3.6/site-packages/ruamel/yaml/constructor.py", line 1469, in construct_mapping
    value = self.construct_object(value_node, deep=deep)
  File "/opt/iib-worker/virtualenv/lib/python3.6/site-packages/ruamel/yaml/constructor.py", line 146, in construct_object
    data = self.construct_non_recursive_object(node)
  File "/opt/iib-worker/virtualenv/lib/python3.6/site-packages/ruamel/yaml/constructor.py", line 181, in construct_non_recursive_object
    data = constructor(self, node)
  File "/opt/iib-worker/virtualenv/lib/python3.6/site-packages/ruamel/yaml/constructor.py", line 1741, in construct_yaml_timestamp
    data = TimeStamp(year, month, day, hour, minute, second, fraction)
  File "/opt/iib-worker/virtualenv/lib/python3.6/site-packages/ruamel/yaml/timestamp.py", line 22, in __new__
    return datetime.datetime.__new__(cls, *args, **kw)  # type: ignore
ValueError: year 0 is out of range

@MartinBasti
Copy link
Contributor

Ah, YAML is automatically creating datetime object

@MartinBasti MartinBasti added the help wanted Extra attention is needed label Dec 2, 2021
@MartinBasti
Copy link
Contributor

Team discussion: just wrap yaml.load call with try: except and provide better error (more context)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants