Skip to content

Commit eaf7a99

Browse files
Backend: Remove AssertionError in non-test code.
1 parent 0878305 commit eaf7a99

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

app/backend/src/couchers/email/rendering.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def render_plaintext_body(*, blocks: list[EmailBlock], footer: EmailFooter, loc_
213213
)
214214
concat.append(line)
215215
case _:
216-
raise AssertionError(f"Unexpected email block type: {block.__class__}")
216+
raise TypeError(f"Unexpected email block type: {block.__class__}")
217217
previous_block = block
218218

219219
concat.append("\n\n")
@@ -306,7 +306,7 @@ def render(
306306
case ActionBlock():
307307
concats.append(self.action_block_template.render(block.__dict__, loc_context))
308308
case _:
309-
raise AssertionError(f"Unexpected email block type: {block.__class__}")
309+
raise TypeError(f"Unexpected email block type: {block.__class__}")
310310

311311
# Render the footer
312312
footer_template_args = footer.to_template_args()

app/backend/src/couchers/notifications/render_email.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -739,13 +739,14 @@ def get_topic_action_unsubscribe_text(topic_action: NotificationTopicAction) ->
739739

740740

741741
def get_topic_key_unsubscribe_text(topic_action: NotificationTopicAction) -> str:
742-
assert can_unsubscribe_topic_key(topic_action)
743-
# Not localized because the design will change so avoid useless work by translators.
744-
match topic_action:
745-
case NotificationTopicAction.chat__message:
746-
return "this chat (mute)"
747-
case _:
748-
raise AssertionError(f"No topic-key description for {topic_action}")
742+
if can_unsubscribe_topic_key(topic_action):
743+
# Not localized because the design will change so avoid useless work by translators.
744+
match topic_action:
745+
case NotificationTopicAction.chat__message:
746+
return "this chat (mute)"
747+
case _:
748+
pass
749+
raise ValueError(f"Topic-action {topic_action} has no unsubscribe text.")
749750

750751

751752
def get_email_footer(user: User, notification: Notification, loc_context: LocalizationContext) -> EmailFooter:

0 commit comments

Comments
 (0)