소스 검색

fix rc and msg if arg parsing throws an exception, fixes #7885

get_args() exception handling before this fix only dealt with
subclasses of "Error", but we have to expect other exceptions
there, too.

In any case, if we have some fatal exception here, we must
terminate with rc 2.

ArgumentTypeError: emit a short error message - usually this is
a user error, invoking borg in a wrong way.

Other exceptions: full info and traceback.
Thomas Waldmann 1 년 전
부모
커밋
77cf77ec38
1개의 변경된 파일11개의 추가작업 그리고 0개의 파일을 삭제
  1. 11 0
      src/borg/archiver/__init__.py

+ 11 - 0
src/borg/archiver/__init__.py

@@ -625,6 +625,17 @@ def main():  # pragma: no cover
                 tb = format_tb(e)
                 print(tb, file=sys.stderr)
             sys.exit(e.exit_code)
+        except argparse.ArgumentTypeError as e:
+            # we might not have logging setup yet, so get out quickly
+            print(str(e), file=sys.stderr)
+            sys.exit(EXIT_ERROR)
+        except Exception:
+            msg = "Local Exception"
+            tb = f"{traceback.format_exc()}\n{sysinfo()}"
+            # we might not have logging setup yet, so get out quickly
+            print(msg, file=sys.stderr)
+            print(tb, file=sys.stderr)
+            sys.exit(EXIT_ERROR)
         try:
             with sig_int:
                 exit_code = archiver.run(args)