Skip to content

Commit

Permalink
Reworking error messages because we can no longer tell which element …
Browse files Browse the repository at this point in the history
…is missing
  • Loading branch information
mew-nsc committed Dec 14, 2021
1 parent fe87fd2 commit 672f1d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
18 changes: 5 additions & 13 deletions importers/jchat_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,33 +140,25 @@ def _read_message_div(self, div, data_store, datafile, change_id):
platform_element = text_blocks[0][1]
msg_content_element = text_blocks[0][2:]

if time_element is None:
if not text_blocks[0] or len(text_blocks[0]) < 3:
self.errors.append(
{self.error_type: f"Unable to read message {msg_id}. No timestamp provided"}
{
self.error_type: f"Unable to read message {msg_id}. Not enough parts (expecting timestamp, platform, message)"
}
)
return

time_string = time_element.text.strip("[").strip("]")
timestamp = self.parse_timestamp(time_string, msg_id)
time_element.record(self.name, "timestamp", timestamp)

if platform_element is None:
self.errors.append(
{self.error_type: f"Unable to read message {msg_id}. No platform provided"}
)
return
platform_quad = platform_element.text[0:4]
platform_element.record(self.name, "platform", platform_quad)
# Match on quadgraphs
platform = self.get_cached_platform_from_quad(data_store, platform_quad, change_id)

if not msg_content_element:
self.errors.append(
{self.error_type: f"Unable to read message {msg_id}. No message provided"}
)
return
msg_content = self.parse_message_content(msg_content_element)
print(msg_content)

if not msg_content:
self.errors.append({self.error_type: f"Unable to parse JChat message {msg_id}."})
return
Expand Down
11 changes: 7 additions & 4 deletions tests/test_load_jchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ def test_invalid_missing_timestamp(self):

check_errors_for_file_contents(
html_string,
"Unable to read message 34544=34534. No timestamp provided",
"Unable to read message 34544=34534. Not enough parts (expecting timestamp, platform, message)",
importer,
"no_timestamp.html",
)
Expand Down Expand Up @@ -590,7 +590,7 @@ def test_invalid_missing_platform(self):

check_errors_for_file_contents(
html_string,
"Unable to read message 34544=34534. No platform provided",
"Unable to read message 34544=34534. Not enough parts (expecting timestamp, platform, message)",
importer,
"no_platform.html",
)
Expand All @@ -615,7 +615,7 @@ def test_invalid_missing_message(self):

check_errors_for_file_contents(
html_string,
"Unable to read message 34544=34534. No message provided",
"Unable to read message 34544=34534. Not enough parts (expecting timestamp, platform, message)",
importer,
"no_message",
)
Expand All @@ -640,7 +640,10 @@ def test_empty_message(self):
importer = JChatImporter()

check_errors_for_file_contents(
html_string, "Unable to parse JChat message 34544=34534.", importer, "no_message"
html_string,
"Unable to read message 34544=34534. Not enough parts (expecting timestamp, platform, message)",
importer,
"no_message",
)

@staticmethod
Expand Down

0 comments on commit 672f1d0

Please sign in to comment.