From 51fc37d57a652398edb6ff955a30e1e26b001059 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Fri, 20 May 2022 13:38:53 -0700 Subject: [PATCH] Improve the error message when a configuration override contains an invalid value (#528). --- NEWS | 1 + borgmatic/config/override.py | 24 ++++++++++++--------- docs/how-to/make-per-application-backups.md | 9 +++++++- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index abafbda..9aafe7e 100644 --- a/NEWS +++ b/NEWS @@ -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.) diff --git a/borgmatic/config/override.py b/borgmatic/config/override.py index 4557e29..8596cb3 100644 --- a/borgmatic/config/override.py +++ b/borgmatic/config/override.py @@ -52,16 +52,20 @@ def parse_overrides(raw_overrides): if not raw_overrides: return () - 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),) - ) - except ValueError: - raise ValueError('Invalid override. Make sure you use the form: SECTION.OPTION=VALUE') - except ruamel.yaml.error.YAMLError as error: - raise ValueError(f'Invalid override value: {error}') + parsed_overrides = [] + + for raw_override in raw_overrides: + try: + raw_keys, value = raw_override.split('=', 1) + parsed_overrides.append((tuple(raw_keys.split('.')), convert_value_type(value),)) + except ValueError: + 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 '{raw_override}': {error.problem}") + + return tuple(parsed_overrides) def apply_overrides(config, raw_overrides): diff --git a/docs/how-to/make-per-application-backups.md b/docs/how-to/make-per-application-backups.md index eeb76ad..9ea496c 100644 --- a/docs/how-to/make-per-application-backups.md +++ b/docs/how-to/make-per-application-backups.md @@ -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