Skip to content

Commit ba93f0d

Browse files
authored
Merge pull request #6972 from thaJeztah/decorate_env_file_error
decorate --env-file, --label-file errors
2 parents ed8c9d7 + 27bee79 commit ba93f0d

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

cli/command/container/opts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,13 +506,13 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
506506
// collect all the environment variables for the container
507507
envVariables, err := opts.ReadKVEnvStrings(copts.envFile.GetSlice(), copts.env.GetSlice())
508508
if err != nil {
509-
return nil, err
509+
return nil, fmt.Errorf("--env-file: %w", err)
510510
}
511511

512512
// collect all the labels for the container
513513
labels, err := opts.ReadKVStrings(copts.labelsFile.GetSlice(), copts.labels.GetSlice())
514514
if err != nil {
515-
return nil, err
515+
return nil, fmt.Errorf("--label-file: %w", err)
516516
}
517517

518518
pidMode := container.PidMode(copts.pidMode)

cli/command/container/opts_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -940,13 +940,13 @@ func TestParseLoggingOpts(t *testing.T) {
940940
}
941941

942942
func TestParseEnvfileVariables(t *testing.T) {
943-
e := "open nonexistent: no such file or directory"
943+
expErr := "--env-file: open nonexistent: no such file or directory"
944944
if runtime.GOOS == "windows" {
945-
e = "open nonexistent: The system cannot find the file specified."
945+
expErr = "--env-file: open nonexistent: The system cannot find the file specified."
946946
}
947947
// env ko
948-
if _, _, _, err := parseRun([]string{"--env-file=nonexistent", "img", "cmd"}); err == nil || err.Error() != e {
949-
t.Fatalf("Expected an error with message '%s', got %v", e, err)
948+
if _, _, _, err := parseRun([]string{"--env-file=nonexistent", "img", "cmd"}); err == nil || err.Error() != expErr {
949+
t.Fatalf("Expected an error with message '%s', got %v", expErr, err)
950950
}
951951
// env ok
952952
config, _, _, err := parseRun([]string{"--env-file=testdata/valid.env", "img", "cmd"})
@@ -993,13 +993,13 @@ func TestParseEnvfileVariablesWithBOMUnicode(t *testing.T) {
993993
}
994994

995995
func TestParseLabelfileVariables(t *testing.T) {
996-
e := "open nonexistent: no such file or directory"
996+
expErr := "--label-file: open nonexistent: no such file or directory"
997997
if runtime.GOOS == "windows" {
998-
e = "open nonexistent: The system cannot find the file specified."
998+
expErr = "--label-file: open nonexistent: The system cannot find the file specified."
999999
}
10001000
// label ko
1001-
if _, _, _, err := parseRun([]string{"--label-file=nonexistent", "img", "cmd"}); err == nil || err.Error() != e {
1002-
t.Fatalf("Expected an error with message '%s', got %v", e, err)
1001+
if _, _, _, err := parseRun([]string{"--label-file=nonexistent", "img", "cmd"}); err == nil || err.Error() != expErr {
1002+
t.Fatalf("Expected an error with message '%s', got %v", expErr, err)
10031003
}
10041004
// label ok
10051005
config, _, _, err := parseRun([]string{"--label-file=testdata/valid.label", "img", "cmd"})

0 commit comments

Comments
 (0)