Parsing time throw a `ValueError` instead of a `ISOFormatError` when parsing garbage

Issue #18 resolved
Guillaume Grasset created an issue

When parsing some invalid string as time, it raise a ValueError. It would be nicer to return a aniso8601.exceptions.ISOFormatError with an explication about the problem, like: ISO 8601 time must start with an integer

running:

aniso8601.parse_time("test")

throw:

ValueError: invalid literal for int() with base 10: 'te'

Comments (4)

  1. Brandon Nielsen repo owner

    There are quite a few of these types of issues that I've either stumbled across, or have been brought to my attention. The custom exception types, ISOFormatError especially, may not have been quite ready for prime time.

    Some others that should throw ISOFormatError:

    >>> aniso8601.parse_datetime('test-06-10T12:00:00Z')
    ...
    ValueError: time data 'test-06-10' does not match format '%Y-%m-%d'
    
    >>> aniso8601.parse_date('test-04-23')
    ...
    ValueError: time data 'test-04-23' does not match format '%Y-%m-%d'
    
    >>> aniso8601.parse_time('test:31:14')
    ...
    ValueError: invalid literal for int() with base 10: 'test'
    
    >>> aniso8601.parse_time('11:test:14')
    ...
    ValueError: invalid literal for int() with base 10: 'test'
    
    >>> aniso8601.parse_time('11:31:test')
    ...
    ValueError: could not convert string to float: test
    
  2. Log in to comment