From 65d8091245afbaf26e81d4e2a54d7101e4e4d0bd Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 28 Nov 2018 01:04:28 +0100 Subject: [PATCH] invalid locations: give err msg containing parsed location, fixes #4179 --- src/borg/helpers/parseformat.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/borg/helpers/parseformat.py b/src/borg/helpers/parseformat.py index 8951b6276..a407763bc 100644 --- a/src/borg/helpers/parseformat.py +++ b/src/borg/helpers/parseformat.py @@ -348,11 +348,11 @@ class Location: """ + optional_archive_re, re.VERBOSE) # archive name (optional, may be empty) def __init__(self, text=''): - self.orig = text - if not self.parse(self.orig): - raise ValueError('Location: parse failed: %s' % self.orig) + if not self.parse(text): + raise ValueError('Invalid location format: "%s"' % self.orig) def parse(self, text): + self.orig = text text = replace_placeholders(text) valid = self._parse(text) if valid: @@ -364,10 +364,9 @@ class Location: if repo is None: return False valid = self._parse(repo) - if not valid: - return False self.archive = m.group('archive') - return True + self.orig = repo if not self.archive else '%s::%s' % (repo, self.archive) + return valid def _parse(self, text): def normpath_special(p): @@ -452,8 +451,8 @@ def location_validator(archive=None, proto=None): def validator(text): try: loc = Location(text) - except ValueError: - raise argparse.ArgumentTypeError('Invalid location format: "%s"' % text) from None + except ValueError as err: + raise argparse.ArgumentTypeError(str(err)) from None if archive is True and not loc.archive: raise argparse.ArgumentTypeError('"%s": No archive specified' % text) elif archive is False and loc.archive: