Skip to content

Commit

Permalink
Added logic to raise a parser error with the appropriate information …
Browse files Browse the repository at this point in the history
…if a Date header is not found in a reply from user section
  • Loading branch information
benne238 committed Jul 1, 2021
1 parent 1d0358c commit f7114c2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/webqueue2api/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ def parse_section(original_string: str, match_start_index: int, tokens: pp.Parse
parsed_item.append(parse_error)
raise ParseError(parse_error["line_num"], f"{parse_error['got']} is a malfomred header or the start of message content without a newline")

if "Date" not in headers.keys():
content_start = tokens_dictionary["content"][0].strip().split("\n", 1)[0]
parse_error = {
"type": "parse_error",
"datetime": format_date_string(str(datetime.datetime.now())),
"expected": "A Date header in the reply from user section",
"got": content_start,
"line_num": original_string[:original_string.find(content_start)].count("\n") + 1
}
raise ParseError(parse_error["line_num"], "Expected a 'Date' header in the reply from user section")

headers_list = []
for key in headers.keys():
headers_list.append({"type": key, "content": headers[key]})
Expand Down

0 comments on commit f7114c2

Please sign in to comment.