mirror of https://github.com/docker/cli.git
opts: remove ErrBadKey as it's not used as a sentinel error
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 commit2b17f4c8a8
. 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]:500c8ba4b6
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
7c85db6e1a
commit
95e221ef4d
13
opts/file.go
13
opts/file.go
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue