Skip to content

Commit 95e221e

Browse files
committed
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 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 <github@gone.nl>
1 parent 7c85db6 commit 95e221e

1 file changed

Lines changed: 2 additions & 11 deletions

File tree

opts/file.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@ import (
1212

1313
const whiteSpaces = " \t"
1414

15-
// ErrBadKey typed error for bad environment variable
16-
type ErrBadKey struct {
17-
msg string
18-
}
19-
20-
func (e ErrBadKey) Error() string {
21-
return "poorly formatted environment: " + e.msg
22-
}
23-
2415
func parseKeyValueFile(filename string, emptyFn func(string) (string, bool)) ([]string, error) {
2516
fh, err := os.Open(filename)
2617
if err != nil {
@@ -51,10 +42,10 @@ func parseKeyValueFile(filename string, emptyFn func(string) (string, bool)) ([]
5142
// trim the front of a variable, but nothing else
5243
variable = strings.TrimLeft(variable, whiteSpaces)
5344
if strings.ContainsAny(variable, whiteSpaces) {
54-
return []string{}, ErrBadKey{fmt.Sprintf("variable '%s' contains whitespaces", variable)}
45+
return []string{}, fmt.Errorf("variable '%s' contains whitespaces", variable)
5546
}
5647
if len(variable) == 0 {
57-
return []string{}, ErrBadKey{fmt.Sprintf("no variable name on line '%s'", line)}
48+
return []string{}, fmt.Errorf("no variable name on line '%s'", line)
5849
}
5950

6051
if hasValue {

0 commit comments

Comments
 (0)