summaryrefslogtreecommitdiff
path: root/alot/helper.py
diff options
context:
space:
mode:
authorBen Finney <ben+python@benfinney.id.au>2018-04-23 16:29:34 +1000
committerBen Finney <ben@benfinney.id.au>2018-04-23 19:54:46 +1000
commit950839f390dbdcd285ceae86b7ddeb4ce62a50d4 (patch)
treebcb22e5900814862b380b3a7fe4f10f7fe013695 /alot/helper.py
parent2441a4d7b3576eb3a1c519713974418638ab82ba (diff)
Raise an exception with a meaningful message.
The `assert` statement is not always executed (it can be optimised away) so is not a suitable run-time check. Also, an exception allows for a better error message.
Diffstat (limited to 'alot/helper.py')
-rw-r--r--alot/helper.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/alot/helper.py b/alot/helper.py
index 4d8d782e..e621f751 100644
--- a/alot/helper.py
+++ b/alot/helper.py
@@ -640,7 +640,9 @@ def email_as_bytes(mail):
# If we get here and the assert triggers it means that different
# parts of the email are encoded differently. I don't think we're
# likely to see that, but it's possible
- assert {'utf-8', 'ascii', 'us-ascii'}.issuperset(charsets), charsets
+ if not {'utf-8', 'ascii', 'us-ascii'}.issuperset(charsets):
+ raise RuntimeError(
+ "different encodings detected: {}".format(charsets))
charset = 'utf-8' # It's a strict super-set
else:
charset = 'utf-8'