diff --git a/management/backup.py b/management/backup.py index bee97e4c..97fc70ad 100755 --- a/management/backup.py +++ b/management/backup.py @@ -192,7 +192,9 @@ def get_passphrase(env): backup_root = os.path.join(env["STORAGE_ROOT"], 'backup') with open(os.path.join(backup_root, 'secret_key.txt'), encoding="utf-8") as f: passphrase = f.readline().strip() - if len(passphrase) < 43: raise Exception("secret_key.txt's first line is too short!") + if len(passphrase) < 43: + msg = "secret_key.txt's first line is too short!" + raise Exception(msg) return passphrase diff --git a/management/dns_update.py b/management/dns_update.py index d9bd82a4..d6f93e55 100755 --- a/management/dns_update.py +++ b/management/dns_update.py @@ -910,8 +910,12 @@ def set_custom_dns_record(qname, rtype, value, action, env): if rtype in {"A", "AAAA"}: if value != "local": # "local" is a special flag for us v = ipaddress.ip_address(value) # raises a ValueError if there's a problem - if rtype == "A" and not isinstance(v, ipaddress.IPv4Address): raise ValueError("That's an IPv6 address.") - if rtype == "AAAA" and not isinstance(v, ipaddress.IPv6Address): raise ValueError("That's an IPv4 address.") + if rtype == "A" and not isinstance(v, ipaddress.IPv4Address): + msg = "That's an IPv6 address." + raise ValueError(msg) + if rtype == "AAAA" and not isinstance(v, ipaddress.IPv6Address): + msg = "That's an IPv4 address." + raise ValueError(msg) elif rtype in {"CNAME", "NS"}: if rtype == "NS" and qname == zone: msg = "NS records can only be set for subdomains." diff --git a/management/mfa.py b/management/mfa.py index 6deab5cf..6cded111 100644 --- a/management/mfa.py +++ b/management/mfa.py @@ -10,7 +10,9 @@ from mailconfig import open_database def get_user_id(email, c): c.execute('SELECT id FROM users WHERE email=?', (email,)) r = c.fetchone() - if not r: raise ValueError("User does not exist.") + if not r: + msg = "User does not exist." + raise ValueError(msg) return r[0] def get_mfa_state(email, env): diff --git a/management/ssl_certificates.py b/management/ssl_certificates.py index 0f7105d9..49fe06c7 100755 --- a/management/ssl_certificates.py +++ b/management/ssl_certificates.py @@ -513,7 +513,9 @@ def check_certificate(domain, ssl_certificate, ssl_private_key, warn_if_expiring try: ssl_cert_chain = load_cert_chain(ssl_certificate) cert = load_pem(ssl_cert_chain[0]) - if not isinstance(cert, Certificate): raise ValueError("This is not a certificate file.") + if not isinstance(cert, Certificate): + msg = "This is not a certificate file." + raise ValueError(msg) except ValueError as e: return (f"There is a problem with the certificate file: {e!s}", None) diff --git a/setup/migrate.py b/setup/migrate.py index ee7346c9..7f2ec60d 100755 --- a/setup/migrate.py +++ b/setup/migrate.py @@ -86,7 +86,9 @@ def migration_7(env): if newemail != email: c = conn.cursor() c.execute("UPDATE aliases SET source=? WHERE source=?", (newemail, email)) - if c.rowcount != 1: raise ValueError("Alias not found.") + if c.rowcount != 1: + msg = "Alias not found." + raise ValueError(msg) print("Updated alias", email, "to", newemail) except Exception as e: print("Error updating IDNA alias", email, e)