From c12fc71bf5b02a9b8ff75dc0ea355e57a461a8ea Mon Sep 17 00:00:00 2001 From: Guinness Date: Sat, 14 Aug 2021 10:12:31 +0200 Subject: [PATCH] Use an exception catching to avoid a stack trace When exclude files are used, this can trigger a stack trace if the file does not exist. Instead exit nicely without the stacktrace. --- src/borg/patterns.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/borg/patterns.py b/src/borg/patterns.py index da12365163..3a53cada02 100644 --- a/src/borg/patterns.py +++ b/src/borg/patterns.py @@ -9,6 +9,7 @@ from . import shellpattern from .helpers import clean_lines +from .helpers import Error def parse_patternfile_line(line, roots, ie_commands, fallback): @@ -53,8 +54,11 @@ def __call__(self, parser, args, values, option_string=None): Lines empty or starting with '#' after stripping whitespace on both line ends are ignored. """ filename = values[0] - with open(filename) as f: - self.parse(f, args) + try: + with open(filename) as f: + self.parse(f, args) + except FileNotFoundError as e: + raise Error(str(e)) def parse(self, fobj, args): load_pattern_file(fobj, args.paths, args.patterns)