diff --git a/src/restic/options/options.go b/src/restic/options/options.go index 49d3fd309..c5d9ff3e3 100644 --- a/src/restic/options/options.go +++ b/src/restic/options/options.go @@ -69,7 +69,8 @@ func (o Options) Extract(ns string) Options { } // Apply sets the options on dst via reflection, using the struct tag `option`. -func (o Options) Apply(dst interface{}) error { +// The namespace argument (ns) is only used for error messages. +func (o Options) Apply(ns string, dst interface{}) error { v := reflect.ValueOf(dst).Elem() fields := make(map[string]reflect.StructField) @@ -92,6 +93,9 @@ func (o Options) Apply(dst interface{}) error { for key, value := range o { field, ok := fields[key] if !ok { + if ns != "" { + key = ns + "." + key + } return errors.Fatalf("option %v is not known", key) } diff --git a/src/restic/options/options_test.go b/src/restic/options/options_test.go index 5a255591c..a5ab83952 100644 --- a/src/restic/options/options_test.go +++ b/src/restic/options/options_test.go @@ -163,7 +163,7 @@ func TestOptionsApply(t *testing.T) { for i, test := range setTests { t.Run(fmt.Sprintf("test-%d", i), func(t *testing.T) { var dst Target - err := test.input.Apply(&dst) + err := test.input.Apply("", &dst) if err != nil { t.Fatal(err) } @@ -176,25 +176,29 @@ func TestOptionsApply(t *testing.T) { } var invalidSetTests = []struct { - input Options - err string + input Options + namespace string + err string }{ { Options{ "first_name": "foobar", }, - "option first_name is not known", + "ns", + "option ns.first_name is not known", }, { Options{ "id": "foobar", }, + "ns", `strconv.ParseInt: parsing "foobar": invalid syntax`, }, { Options{ "timeout": "2134", }, + "ns", `time: missing unit in duration 2134`, }, } @@ -203,7 +207,7 @@ func TestOptionsApplyInvalid(t *testing.T) { for i, test := range invalidSetTests { t.Run(fmt.Sprintf("test-%d", i), func(t *testing.T) { var dst Target - err := test.input.Apply(&dst) + err := test.input.Apply(test.namespace, &dst) if err == nil { t.Fatalf("expected error %v not found", test.err) }