1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2025-01-24 12:47:05 +00:00

Fixed EM102 (f-string-in-exception): Exception must not use an f-string literal, assign to variable first

This commit is contained in:
Teal Dulcet 2025-01-08 05:22:41 -08:00
parent c357fe83d2
commit 350b5b035a
4 changed files with 16 additions and 8 deletions

View File

@ -590,7 +590,8 @@ def get_dns_zonefile(zone, env):
if zone == domain:
break
else:
raise ValueError(f"{zone} is not a domain name that corresponds to a zone.")
msg = f"{zone} is not a domain name that corresponds to a zone."
raise ValueError(msg)
nsd_zonefile = "/etc/nsd/zones/" + fn
with open(nsd_zonefile, encoding="utf-8") as f:
@ -896,7 +897,8 @@ def set_custom_dns_record(qname, rtype, value, action, env):
else:
# No match.
if qname != "_secondary_nameserver":
raise ValueError(f"{qname} is not a domain name or a subdomain of a domain name managed by this box.")
msg = f"{qname} is not a domain name or a subdomain of a domain name managed by this box."
raise ValueError(msg)
# validate rtype
rtype = rtype.upper()
@ -926,7 +928,8 @@ def set_custom_dns_record(qname, rtype, value, action, env):
# anything goes
pass
else:
raise ValueError(f"Unknown record type '{rtype}'.")
msg = f"Unknown record type '{rtype}'."
raise ValueError(msg)
# load existing config
config = list(get_custom_dns_config(env))
@ -1037,7 +1040,8 @@ def set_secondary_dns(hostnames, env):
try:
resolver.resolve(item, "AAAA")
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, dns.resolver.Timeout):
raise ValueError(f"Could not resolve the IP address of {item}.")
msg = f"Could not resolve the IP address of {item}."
raise ValueError(msg)
else:
# Validate IP address.
try:
@ -1046,7 +1050,8 @@ def set_secondary_dns(hostnames, env):
else:
ipaddress.ip_address(item[4:]) # raises a ValueError if there's a problem
except ValueError:
raise ValueError(f"'{item[4:]}' is not an IPv4 or IPv6 address or subnet.")
msg = f"'{item[4:]}' is not an IPv4 or IPv6 address or subnet."
raise ValueError(msg)
# Set.
set_custom_dns_record("_secondary_nameserver", "A", " ".join(hostnames), "set", env)

View File

@ -608,7 +608,8 @@ def valid_date(string):
try:
date = dateutil.parser.parse(string)
except ValueError:
raise argparse.ArgumentTypeError(f"Unrecognized date and/or time '{string}'")
msg = f"Unrecognized date and/or time '{string}'"
raise argparse.ArgumentTypeError(msg)
return date

View File

@ -341,7 +341,8 @@ def get_mail_password(email, env):
c.execute('SELECT password FROM users WHERE email=?', (email,))
rows = c.fetchall()
if len(rows) != 1:
raise ValueError(f"That's not a user ({email}).")
msg = f"That's not a user ({email})."
raise ValueError(msg)
return rows[0][0]
def remove_mail_user(email, env):

View File

@ -142,7 +142,8 @@ def http_test(url, expected_status, postdata=None, qsargs=None, auth=None):
# return response status code
if r.status_code != expected_status:
r.raise_for_status() # anything but 200
raise OSError(f"Got unexpected status code {r.status_code}.")
msg = f"Got unexpected status code {r.status_code}."
raise OSError(msg)
# define how to run a test