mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2025-01-23 12:37:05 +00:00
Fixed TRY003 (raise-vanilla-args): Avoid specifying long messages outside the exception class
This commit is contained in:
parent
1d1a1a09c4
commit
08329c18cd
@ -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
|
||||
|
||||
|
@ -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."
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user