From f86a13c43878d318a357794aea1f01ddebda1ad2 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 25 Oct 2023 11:06:37 +0200 Subject: [PATCH 1/2] fix invalid pattern argument error msg --- src/borg/patterns.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/borg/patterns.py b/src/borg/patterns.py index 58c3480c8..74c6ad831 100644 --- a/src/borg/patterns.py +++ b/src/borg/patterns.py @@ -368,7 +368,7 @@ def parse_inclexcl_command(cmd_line_str, fallback=ShellPattern): cmd = cmd_prefix_map.get(cmd_line_str[0]) if cmd is None: - raise argparse.ArgumentTypeError("A pattern/command must start with anyone of: %s" % ", ".join(cmd_prefix_map)) + raise argparse.ArgumentTypeError("A pattern/command must start with any of: %s" % ", ".join(cmd_prefix_map)) # remaining text on command-line following the command character remainder_str = cmd_line_str[1:].lstrip() From 77cf77ec383f2bdb754580c1083666be438bab47 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 25 Oct 2023 12:06:27 +0200 Subject: [PATCH 2/2] 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. --- src/borg/archiver/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/borg/archiver/__init__.py b/src/borg/archiver/__init__.py index e62783555..e8532a248 100644 --- a/src/borg/archiver/__init__.py +++ b/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)