SimplyKnownAsG / yamlize

Python YAML serializing library
Apache License 2.0
11 stars 5 forks source link

parsing bad type does not give the location in file #2

Open SimplyKnownAsG opened 6 years ago

SimplyKnownAsG commented 6 years ago

The below example demonstrates there is no context reported in the error.

>>> import yamlize
>>> @yamlize.yamlizable(yamlize.Attribute('attr', type=int))
... class Thing(object):
...     pass
...
>>> Thing.load('attr: ')
Traceback (most recent call last):
  File "C:\Users\gmalmgren\codes\yamlize\yamlize\yamlizable.py", line 121, in from_yaml
    new_value = cls.__type(data)  # to coerce to correct type
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\gmalmgren\codes\yamlize\yamlize\yamlizable.py", line 60, in load
    return cls.from_yaml(loader, node, None)
  File "C:\Users\gmalmgren\codes\yamlize\yamlize\objects.py", line 102, in from_yaml
    self.__from_node(loader, node)
  File "C:\Users\gmalmgren\codes\yamlize\yamlize\objects.py", line 159, in __from_node
    attribute = attrs.from_yaml(self, loader, key_node, val_node, self.__round_trip_data)
  File "C:\Users\gmalmgren\codes\yamlize\yamlize\attribute_collection.py", line 59, in from_yaml
    attribute.from_yaml(obj, loader, val_node, round_trip_data)
  File "C:\Users\gmalmgren\codes\yamlize\yamlize\attributes.py", line 143, in from_yaml
    value = self.type.from_yaml(loader, node, round_trip_data)
  File "C:\Users\gmalmgren\codes\yamlize\yamlize\yamlizable.py", line 127, in from_yaml
    .format(data, cls))
yamlize.yamlizing_error.YamlizingError: Failed to coerce data `None` to type `<class 'yamlize.yamlizable.Yamlizableint'>