Handle None values when doing conversions and catch indexing errors
This commit is contained in:
parent
c50de9bed7
commit
1803a37591
@ -73,6 +73,8 @@ class MetadataFormatter(string.Formatter):
|
||||
return cast(str, super().format_field(value, format_spec))
|
||||
|
||||
def convert_field(self, value: Any, conversion: str | None) -> str:
|
||||
if value is None:
|
||||
return ""
|
||||
if isinstance(value, Iterable) and not isinstance(value, (str, tuple)):
|
||||
if conversion == "C":
|
||||
if isinstance(value, Sized):
|
||||
@ -182,8 +184,11 @@ class MetadataFormatter(string.Formatter):
|
||||
|
||||
# given the field_name, find the object it references
|
||||
# and the argument it came from
|
||||
obj, arg_used = self.get_field(field_name, args, kwargs)
|
||||
used_args.add(arg_used)
|
||||
try:
|
||||
obj, arg_used = self.get_field(field_name, args, kwargs)
|
||||
used_args.add(arg_used)
|
||||
except Exception:
|
||||
obj = None
|
||||
|
||||
obj = self.none_replacement(obj, replacement, r)
|
||||
# do any conversion on the resulting object
|
||||
|
@ -1114,6 +1114,22 @@ for p in names:
|
||||
)
|
||||
|
||||
file_renames = [
|
||||
(
|
||||
"{series} #{issue} - {title} ({year}) ({price!c})", # conversion on None
|
||||
False,
|
||||
False,
|
||||
"universal",
|
||||
"Cory Doctorow's Futuristic Tales of the Here and Now #001 - Anda's Game (2007).cbz",
|
||||
does_not_raise(),
|
||||
),
|
||||
(
|
||||
"{country[0]} {price} {year}", # Indexing a None value
|
||||
False,
|
||||
False,
|
||||
"universal",
|
||||
"2007.cbz",
|
||||
does_not_raise(),
|
||||
),
|
||||
(
|
||||
"{series!c} {price} {year}", # Capitalize
|
||||
False,
|
||||
|
Loading…
Reference in New Issue
Block a user