diff --git a/comictaggerlib/filerenamer.py b/comictaggerlib/filerenamer.py index 3ef5bbf..8556b92 100644 --- a/comictaggerlib/filerenamer.py +++ b/comictaggerlib/filerenamer.py @@ -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 diff --git a/testing/filenames.py b/testing/filenames.py index 9c7da07..14a1c6d 100644 --- a/testing/filenames.py +++ b/testing/filenames.py @@ -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,