Skip to content

Commit

Permalink
opts: remove ErrBadKey as it's not used as a sentinel error
Browse files Browse the repository at this point in the history
This error was originally introduced `ErrBadEnvVariable` in [moby/moby@500c8ba],
but merely for convenience, and not used as a sentinel error. After the code
was moved from the daemon to the cli repository, it was renamed to be more
generic `ErrBadKey` in commit 2b17f4c.

A search on GitHub shows that there's no consumers using this error as
sentinel error, and it's not used in our own code as such, so it should
be safe to remove this error.

This patch removes the `ErrBadKey` error-type; it also removes the prefix
(`poorly formatted environment:`) to make the error more generic, because
the same function was used both for env-files and label-files.

[moby/moby@500c8ba]: vdemeester/moby@500c8ba

Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Oct 3, 2024
1 parent 7c85db6 commit 95e221e
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions opts/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ import (

const whiteSpaces = " \t"

// ErrBadKey typed error for bad environment variable
type ErrBadKey struct {
msg string
}

func (e ErrBadKey) Error() string {
return "poorly formatted environment: " + e.msg
}

func parseKeyValueFile(filename string, emptyFn func(string) (string, bool)) ([]string, error) {
fh, err := os.Open(filename)
if err != nil {
Expand Down Expand Up @@ -51,10 +42,10 @@ func parseKeyValueFile(filename string, emptyFn func(string) (string, bool)) ([]
// trim the front of a variable, but nothing else
variable = strings.TrimLeft(variable, whiteSpaces)
if strings.ContainsAny(variable, whiteSpaces) {
return []string{}, ErrBadKey{fmt.Sprintf("variable '%s' contains whitespaces", variable)}
return []string{}, fmt.Errorf("variable '%s' contains whitespaces", variable)
}
if len(variable) == 0 {
return []string{}, ErrBadKey{fmt.Sprintf("no variable name on line '%s'", line)}
return []string{}, fmt.Errorf("no variable name on line '%s'", line)
}

if hasValue {
Expand Down

0 comments on commit 95e221e

Please sign in to comment.