Improve the error message when a configuration override contains an invalid value (#528).

This commit is contained in:
Dan Helfman 2022-05-20 13:38:53 -07:00
parent 1921f55a9d
commit 51fc37d57a
3 changed files with 23 additions and 11 deletions

1
NEWS
View file

@ -1,4 +1,5 @@
1.6.1.dev0
* #528: Improve the error message when a configuration override contains an invalid value.
* #532: When a configuration include is a relative path, load it from either the current working
directory or from the directory containing the file doing the including. (Previously, only the
working directory was used.)

View file

@ -52,16 +52,20 @@ def parse_overrides(raw_overrides):
if not raw_overrides:
return ()
parsed_overrides = []
for raw_override in raw_overrides:
try:
return tuple(
(tuple(raw_keys.split('.')), convert_value_type(value))
for raw_override in raw_overrides
for raw_keys, value in (raw_override.split('=', 1),)
)
raw_keys, value = raw_override.split('=', 1)
parsed_overrides.append((tuple(raw_keys.split('.')), convert_value_type(value),))
except ValueError:
raise ValueError('Invalid override. Make sure you use the form: SECTION.OPTION=VALUE')
raise ValueError(
f"Invalid override '{raw_override}'. Make sure you use the form: SECTION.OPTION=VALUE"
)
except ruamel.yaml.error.YAMLError as error:
raise ValueError(f'Invalid override value: {error}')
raise ValueError(f"Invalid override '{raw_override}': {error.problem}")
return tuple(parsed_overrides)
def apply_overrides(config, raw_overrides):

View file

@ -176,7 +176,14 @@ borgmatic create --override location.repositories=[test1.borg,test2.borg]
Or even a single list element:
```bash
borgmatic create --override location.repositories=[/root/test1.borg]
borgmatic create --override location.repositories=[/root/test.borg]
```
If your override value contains special YAML characters like colons, then
you'll need quotes for it to parse correctly:
```bash
borgmatic create --override location.repositories="['user@server:test.borg']"
```
There is not currently a way to override a single element of a list without