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.

Fix #5734
This commit is contained in:
Guinness 2021-08-13 16:55:21 +02:00
parent b65183fc48
commit 82e93527b0
No known key found for this signature in database
GPG Key ID: 452A734DA611FA7C
1 changed files with 6 additions and 2 deletions

View File

@ -9,6 +9,7 @@ from enum import Enum
from . import shellpattern from . import shellpattern
from .helpers import clean_lines from .helpers import clean_lines
from .helpers.errors import Error
def parse_patternfile_line(line, roots, ie_commands, fallback): def parse_patternfile_line(line, roots, ie_commands, fallback):
@ -53,8 +54,11 @@ class ArgparsePatternFileAction(argparse.Action):
Lines empty or starting with '#' after stripping whitespace on both line ends are ignored. Lines empty or starting with '#' after stripping whitespace on both line ends are ignored.
""" """
filename = values[0] filename = values[0]
try:
with open(filename) as f: with open(filename) as f:
self.parse(f, args) self.parse(f, args)
except FileNotFoundError as e:
raise Error(str(e))
def parse(self, fobj, args): def parse(self, fobj, args):
load_pattern_file(fobj, args.paths, args.patterns) load_pattern_file(fobj, args.paths, args.patterns)