mirror of
https://github.com/borgbackup/borg.git
synced 2025-01-03 05:35:58 +00:00
Merge pull request #4186 from ThomasWaldmann/location-parse-error-msg
invalid locations: give err msg containing parsed location, fixes #4179
This commit is contained in:
commit
6afd69ae09
1 changed files with 7 additions and 8 deletions
|
@ -348,11 +348,11 @@ class Location:
|
||||||
""" + optional_archive_re, re.VERBOSE) # archive name (optional, may be empty)
|
""" + optional_archive_re, re.VERBOSE) # archive name (optional, may be empty)
|
||||||
|
|
||||||
def __init__(self, text=''):
|
def __init__(self, text=''):
|
||||||
self.orig = text
|
if not self.parse(text):
|
||||||
if not self.parse(self.orig):
|
raise ValueError('Invalid location format: "%s"' % self.orig)
|
||||||
raise ValueError('Location: parse failed: %s' % self.orig)
|
|
||||||
|
|
||||||
def parse(self, text):
|
def parse(self, text):
|
||||||
|
self.orig = text
|
||||||
text = replace_placeholders(text)
|
text = replace_placeholders(text)
|
||||||
valid = self._parse(text)
|
valid = self._parse(text)
|
||||||
if valid:
|
if valid:
|
||||||
|
@ -364,10 +364,9 @@ def parse(self, text):
|
||||||
if repo is None:
|
if repo is None:
|
||||||
return False
|
return False
|
||||||
valid = self._parse(repo)
|
valid = self._parse(repo)
|
||||||
if not valid:
|
|
||||||
return False
|
|
||||||
self.archive = m.group('archive')
|
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 _parse(self, text):
|
||||||
def normpath_special(p):
|
def normpath_special(p):
|
||||||
|
@ -452,8 +451,8 @@ def location_validator(archive=None, proto=None):
|
||||||
def validator(text):
|
def validator(text):
|
||||||
try:
|
try:
|
||||||
loc = Location(text)
|
loc = Location(text)
|
||||||
except ValueError:
|
except ValueError as err:
|
||||||
raise argparse.ArgumentTypeError('Invalid location format: "%s"' % text) from None
|
raise argparse.ArgumentTypeError(str(err)) from None
|
||||||
if archive is True and not loc.archive:
|
if archive is True and not loc.archive:
|
||||||
raise argparse.ArgumentTypeError('"%s": No archive specified' % text)
|
raise argparse.ArgumentTypeError('"%s": No archive specified' % text)
|
||||||
elif archive is False and loc.archive:
|
elif archive is False and loc.archive:
|
||||||
|
|
Loading…
Reference in a new issue