From f7114c235055346483be625d2e115686bf17a636 Mon Sep 17 00:00:00 2001 From: benne238 Date: Thu, 1 Jul 2021 10:28:19 -0400 Subject: [PATCH] Added logic to raise a parser error with the appropriate information if a Date header is not found in a reply from user section --- src/webqueue2api/parser/parser.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/webqueue2api/parser/parser.py b/src/webqueue2api/parser/parser.py index 0252e29..29af2f4 100644 --- a/src/webqueue2api/parser/parser.py +++ b/src/webqueue2api/parser/parser.py @@ -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]})