diff --git a/cli/command/container/opts.go b/cli/command/container/opts.go index f9d896882ebf..905674627dbb 100644 --- a/cli/command/container/opts.go +++ b/cli/command/container/opts.go @@ -506,13 +506,13 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con // collect all the environment variables for the container envVariables, err := opts.ReadKVEnvStrings(copts.envFile.GetSlice(), copts.env.GetSlice()) if err != nil { - return nil, err + return nil, fmt.Errorf("--env-file: %w", err) } // collect all the labels for the container labels, err := opts.ReadKVStrings(copts.labelsFile.GetSlice(), copts.labels.GetSlice()) if err != nil { - return nil, err + return nil, fmt.Errorf("--label-file: %w", err) } pidMode := container.PidMode(copts.pidMode) diff --git a/cli/command/container/opts_test.go b/cli/command/container/opts_test.go index 51a0e72b4943..394cf1f467bb 100644 --- a/cli/command/container/opts_test.go +++ b/cli/command/container/opts_test.go @@ -937,13 +937,13 @@ func TestParseLoggingOpts(t *testing.T) { } func TestParseEnvfileVariables(t *testing.T) { - e := "open nonexistent: no such file or directory" + expErr := "--env-file: open nonexistent: no such file or directory" if runtime.GOOS == "windows" { - e = "open nonexistent: The system cannot find the file specified." + expErr = "--env-file: open nonexistent: The system cannot find the file specified." } // env ko - if _, _, _, err := parseRun([]string{"--env-file=nonexistent", "img", "cmd"}); err == nil || err.Error() != e { - t.Fatalf("Expected an error with message '%s', got %v", e, err) + if _, _, _, err := parseRun([]string{"--env-file=nonexistent", "img", "cmd"}); err == nil || err.Error() != expErr { + t.Fatalf("Expected an error with message '%s', got %v", expErr, err) } // env ok config, _, _, err := parseRun([]string{"--env-file=testdata/valid.env", "img", "cmd"}) @@ -990,13 +990,13 @@ func TestParseEnvfileVariablesWithBOMUnicode(t *testing.T) { } func TestParseLabelfileVariables(t *testing.T) { - e := "open nonexistent: no such file or directory" + expErr := "--label-file: open nonexistent: no such file or directory" if runtime.GOOS == "windows" { - e = "open nonexistent: The system cannot find the file specified." + expErr = "--label-file: open nonexistent: The system cannot find the file specified." } // label ko - if _, _, _, err := parseRun([]string{"--label-file=nonexistent", "img", "cmd"}); err == nil || err.Error() != e { - t.Fatalf("Expected an error with message '%s', got %v", e, err) + if _, _, _, err := parseRun([]string{"--label-file=nonexistent", "img", "cmd"}); err == nil || err.Error() != expErr { + t.Fatalf("Expected an error with message '%s', got %v", expErr, err) } // label ok config, _, _, err := parseRun([]string{"--label-file=testdata/valid.label", "img", "cmd"})