diff --git a/nvchecker/__main__.py b/nvchecker/__main__.py index b84358b..602e7b9 100755 --- a/nvchecker/__main__.py +++ b/nvchecker/__main__.py @@ -33,8 +33,8 @@ def main() -> None: try: entries, options = core.load_file( args.file, use_keymanager=not bool(args.keyfile)) - except FileNotFoundError: - sys.exit('version configuration file not given and default does not exist') + except core.FileLoadError as e: + sys.exit(str(e)) if args.keyfile: keymanager = KeyManager(Path(args.keyfile)) diff --git a/nvchecker/core.py b/nvchecker/core.py index e74a88a..8b320d5 100644 --- a/nvchecker/core.py +++ b/nvchecker/core.py @@ -140,11 +140,23 @@ class Options(NamedTuple): proxy: Optional[str] keymanager: KeyManager +class FileLoadError(Exception): + def __init__(self, kind, exc): + self.kind = kind + self.exc = exc + + def __str__(self): + return f'failed to load {self.kind}: {self.exc}' + def load_file( file: str, *, use_keymanager: bool, ) -> Tuple[Entries, Options]: - config = toml.load(file) + try: + config = toml.load(file) + except OSError as e: + raise FileLoadError('version configuration file', e) + ver_files: Optional[Tuple[Path, Path]] = None keymanager = KeyManager(None) @@ -167,7 +179,10 @@ def load_file( keyfile_s = os.path.expandvars( os.path.expanduser(c.get('keyfile'))) keyfile = d / keyfile_s - keymanager = KeyManager(keyfile) + try: + keymanager = KeyManager(keyfile) + except OSError as e: + raise FileLoadError('keyfile', e) max_concurrency = c.get('max_concurrency', 20) proxy = c.get('proxy')