forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
60 lines (53 loc) · 1.52 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package errors
import (
"path/filepath"
)
// GenerationError is an error returned from config generators
type GenerationError int
const (
NoGit GenerationError = iota + 1
SourceDirAndURL
InvalidSourceDir
CouldNotDetect
NoBuilderFound
InvalidDockerfile
ImageNotFound
)
func (e GenerationError) Error() string {
switch e {
case NoGit:
return "git was not detected in your system. It is needed for build config generation."
case SourceDirAndURL:
return "a source directory and a source URL were specified. Please only specify one."
case InvalidSourceDir:
return "the source directory is not readable or is invalid."
case CouldNotDetect:
return "could not detect a build type from the source."
case NoBuilderFound:
return "could not find a builder to match the source-to-image source repository."
case InvalidDockerfile:
return "invalid Dockerfile. Does not contain a FROM clause."
case ImageNotFound:
return "image data could not be found."
}
return ""
}
// MultipleDockerfiles creates an error caused by multiple Dockerfiles existing in a repository
func NewMultipleDockerfilesErr(paths []string) error {
err := multipleDockerFilesError{}
err = append(err, paths...)
return err
}
type multipleDockerFilesError []string
func (e multipleDockerFilesError) Error() string {
result := "multiple Dockerfile(s) found.\nSpecify one of the following flags:\n"
for _, f := range e {
dir := filepath.Dir(f)
if dir == "" {
dir = "."
}
result += "--docker-context=\"" + dir + "\""
result += "\n"
}
return result
}