Explorar o código

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

Dan Helfman %!s(int64=3) %!d(string=hai) anos
pai
achega
51fc37d57a
Modificáronse 3 ficheiros con 23 adicións e 11 borrados
  1. 1 0
      NEWS
  2. 14 10
      borgmatic/config/override.py
  3. 8 1
      docs/how-to/make-per-application-backups.md

+ 1 - 0
NEWS

@@ -1,4 +1,5 @@
 1.6.1.dev0
 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
  * #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
    directory or from the directory containing the file doing the including. (Previously, only the
    working directory was used.)
    working directory was used.)

+ 14 - 10
borgmatic/config/override.py

@@ -52,16 +52,20 @@ def parse_overrides(raw_overrides):
     if not raw_overrides:
     if not raw_overrides:
         return ()
         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):
 def apply_overrides(config, raw_overrides):

+ 8 - 1
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:
 Or even a single list element:
 
 
 ```bash
 ```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
 There is not currently a way to override a single element of a list without