Commit 87ce55dd authored by Lysander Trischler's avatar Lysander Trischler

Fail twt parsing with a more appropriate message

parent 24bed2d2
......@@ -366,6 +366,10 @@ class ParseTwtTest(unittest.TestCase):
tokens=[Text(start_pos=0, end_pos=11, text="Hello World")]),
parse_twt("2021-09-23T01:14:34+02:00\tHello World", source))
def test_parsing_invalid_twt_with_missing_tab_fails(self):
with self.assertRaisesRegex(ValueError, "invalid twt: tab missing"):
parse_twt("2021-09-23T01:14:34:+02:00 Hello World")
def test_parsing_invalid_timestamp_fails(self):
with self.assertRaises(dateutil.parser.ParserError):
parse_twt("2021-09-23 01:14:70+02:00\tHello World")
......
......@@ -266,7 +266,10 @@ def parse_twt(line, source=None):
proper twt.
"""
created_at, text = line.split("\t", 1)
try:
created_at, text = line.split("\t", 1)
except:
raise ValueError("invalid twt: tab missing") from None
created_at = dateutil.parser.parse(created_at)
if not created_at.tzinfo:
# default to UTC if timezone is missing
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment