cargo-inspector: don't print the traceback if a file is missing

$ cargo-inspector -n zola
Traceback (most recent call last):
  File "/usr/bin/cargo-inspector", line 33, in <module>
    sys.exit(load_entry_point('rust2rpm==18', 'console_scripts', 'cargo-inspector')())
  File "/home/zbyszek/python/rust2rpm/rust2rpm/inspector.py", line 78, in main
    files = [_cargo_toml(args.path, f) for f in files]
  File "/home/zbyszek/python/rust2rpm/rust2rpm/inspector.py", line 78, in <listcomp>
    files = [_cargo_toml(args.path, f) for f in files]
  File "/home/zbyszek/python/rust2rpm/rust2rpm/inspector.py", line 50, in _cargo_toml
    raise FileNotFoundError(f'Cargo.toml not found for binary {binary_or_cargo_toml}')
FileNotFoundError: Cargo.toml not found for binary zola

becomes

$ cargo-inspector -n zola
FileNotFoundError: Cargo.toml not found for binary zola
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2021-10-13 13:13:44 +02:00 committed by zbyszek
parent aa849b8aa5
commit 7b853072f5

View file

@ -310,6 +310,8 @@ def exit_on_common_errors():
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
cmd = shlex.join(e.cmd) cmd = shlex.join(e.cmd)
sys.exit(f'Subcommand failed with code {e.returncode}: {cmd}') sys.exit(f'Subcommand failed with code {e.returncode}: {cmd}')
except FileNotFoundError as e:
sys.exit(str(e))
@exit_on_common_errors() @exit_on_common_errors()