forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
194 lines (175 loc) · 5.61 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package errors
import (
"fmt"
)
// Common STI errors
const (
InspectImageError int = 1 + iota
PullImageError
SaveArtifactsError
AssembleError
WorkdirError
BuildError
TarTimeoutError
DownloadError
ScriptsInsideImageError
InstallError
InstallErrorRequired
URLHandlerError
STIContainerError
)
// Error represents an error thrown during STI execution
type Error struct {
Message string
Details error
ErrorCode int
Suggestion string
}
// ContainerError is an error returned when a container exits with a non-zero code.
// ExitCode contains the exit code from the container
type ContainerError struct {
Message string
Output string
ErrorCode int
Suggestion string
ExitCode int
}
// Error returns a string for a given error
func (s Error) Error() string {
return s.Message
}
// Error returns a string for the given error
func (s ContainerError) Error() string {
return s.Message
}
// NewInspectImageError returns a new error which indicates there was a problem
// inspecting the image
func NewInspectImageError(name string, err error) error {
return Error{
Message: fmt.Sprintf("unable to get metadata for %s", name),
Details: err,
ErrorCode: InspectImageError,
Suggestion: "check image name",
}
}
// NewPullImageError returns a new error which indicates there was a problem
// pulling the image
func NewPullImageError(name string, err error) error {
return Error{
Message: fmt.Sprintf("unable to get %s", name),
Details: err,
ErrorCode: PullImageError,
Suggestion: "check image name, or if using local image add --forcePull=false flag",
}
}
// NewSaveArtifactsError returns a new error which indicates there was a problem
// calling save-artifacts script
func NewSaveArtifactsError(name, output string, err error) error {
return Error{
Message: fmt.Sprintf("saving artifacts for %s failed:\n%s", name, output),
Details: err,
ErrorCode: SaveArtifactsError,
Suggestion: "check the save-artifacts script for errors",
}
}
// NewAssembleError returns a new error which indicates there was a problem
// running assemble script
func NewAssembleError(name, output string, err error) error {
return Error{
Message: fmt.Sprintf("assemble for %s failed:\n%s", name, output),
Details: err,
ErrorCode: AssembleError,
Suggestion: "check the assemble script output for errors",
}
}
// NewWorkDirError returns a new error which indicates there was a problem
// when creating working directory
func NewWorkDirError(dir string, err error) error {
return Error{
Message: fmt.Sprintf("creating temporary directory %s failed", dir),
Details: err,
ErrorCode: WorkdirError,
Suggestion: "check if you have access to your system's temporary directory",
}
}
// NewBuildError returns a new error which indicates there was a problem
// building the image
func NewBuildError(name string, err error) error {
return Error{
Message: fmt.Sprintf("building %s failed", name),
Details: err,
ErrorCode: BuildError,
Suggestion: "check the build output for errors",
}
}
// NewTarTimeoutError returns a new error which indicates there was a problem
// when sending or receiving tar stream
func NewTarTimeoutError() error {
return Error{
Message: fmt.Sprintf("timeout waiting for tar stream"),
Details: nil,
ErrorCode: TarTimeoutError,
Suggestion: "check the sti-helper script if it accepts tar stream for assemble and sends for save-artifacts",
}
}
// NewDownloadError returns a new error which indicates there was a problem
// when downloading a file
func NewDownloadError(url string, code int) error {
return Error{
Message: fmt.Sprintf("failed to retrieve %s, response code %d", url, code),
Details: nil,
ErrorCode: DownloadError,
Suggestion: "check the availability of the address",
}
}
// NewScriptsInsideImageError returns a new error which informs of scripts
// being placed inside the image
func NewScriptsInsideImageError(url string) error {
return Error{
Message: fmt.Sprintf("scripts inside the image: %s", url),
Details: nil,
ErrorCode: ScriptsInsideImageError,
Suggestion: "",
}
}
// NewInstallError returns a new error which indicates there was a problem
// when downloading a script
func NewInstallError(script string) error {
return Error{
Message: fmt.Sprintf("failed to install %v", script),
Details: nil,
ErrorCode: InstallError,
Suggestion: "provide URL with STI scripts with -s flag or check the image if it contains STI_SCRIPTS_URL variable set",
}
}
// NewInstallRequiredError returns a new error which indicates there was a problem
// when downloading a required script
func NewInstallRequiredError(scripts []string) error {
return Error{
Message: fmt.Sprintf("failed to install %v", scripts),
Details: nil,
ErrorCode: InstallErrorRequired,
Suggestion: "provide URL with STI scripts with -s flag or check the image if it contains STI_SCRIPTS_URL variable set",
}
}
// NewURLHandlerError returns a new error which indicates there was a problem
// when trying to read scripts URL
func NewURLHandlerError(url string) error {
return Error{
Message: fmt.Sprintf("no URL handler for %s", url),
Details: nil,
ErrorCode: URLHandlerError,
Suggestion: "check the URL",
}
}
// NewContainerError return a new error which indicates there was a problem
// invoking command inside container
func NewContainerError(name string, code int, output string) error {
return ContainerError{
Message: fmt.Sprintf("non-zero (%d) exit code from %s", code, name),
Output: output,
ErrorCode: STIContainerError,
Suggestion: "check the container logs for more information on the failure",
ExitCode: code,
}
}