...
1
2
3 package hcsshim
4
5 import (
6 "fmt"
7 "syscall"
8
9 "github.com/Microsoft/hcsshim/internal/hns"
10
11 "github.com/Microsoft/hcsshim/internal/hcs"
12 "github.com/Microsoft/hcsshim/internal/hcserror"
13 )
14
15 var (
16
17 ErrComputeSystemDoesNotExist = hcs.ErrComputeSystemDoesNotExist
18
19
20 ErrElementNotFound = hcs.ErrElementNotFound
21
22
23 ErrNotSupported = hcs.ErrNotSupported
24
25
26
27 ErrInvalidData = hcs.ErrInvalidData
28
29
30 ErrHandleClose = hcs.ErrHandleClose
31
32
33 ErrAlreadyClosed = hcs.ErrAlreadyClosed
34
35
36 ErrInvalidNotificationType = hcs.ErrInvalidNotificationType
37
38
39 ErrInvalidProcessState = hcs.ErrInvalidProcessState
40
41
42 ErrTimeout = hcs.ErrTimeout
43
44
45
46 ErrUnexpectedContainerExit = hcs.ErrUnexpectedContainerExit
47
48
49
50 ErrUnexpectedProcessAbort = hcs.ErrUnexpectedProcessAbort
51
52
53 ErrUnexpectedValue = hcs.ErrUnexpectedValue
54
55
56 ErrOperationDenied = hcs.ErrOperationDenied
57
58
59 ErrVmcomputeAlreadyStopped = hcs.ErrVmcomputeAlreadyStopped
60
61
62 ErrVmcomputeOperationPending = hcs.ErrVmcomputeOperationPending
63
64
65 ErrVmcomputeOperationInvalidState = hcs.ErrVmcomputeOperationInvalidState
66
67
68 ErrProcNotFound = hcs.ErrProcNotFound
69
70
71
72 ErrVmcomputeOperationAccessIsDenied = hcs.ErrVmcomputeOperationAccessIsDenied
73
74
75 ErrVmcomputeInvalidJSON = hcs.ErrVmcomputeInvalidJSON
76
77
78 ErrVmcomputeUnknownMessage = hcs.ErrVmcomputeUnknownMessage
79
80
81 ErrPlatformNotSupported = hcs.ErrPlatformNotSupported
82 )
83
84 type EndpointNotFoundError = hns.EndpointNotFoundError
85 type NetworkNotFoundError = hns.NetworkNotFoundError
86
87
88 type ProcessError struct {
89 Process *process
90 Operation string
91 Err error
92 Events []hcs.ErrorEvent
93 }
94
95
96 type ContainerError struct {
97 Container *container
98 Operation string
99 Err error
100 Events []hcs.ErrorEvent
101 }
102
103 func (e *ContainerError) Error() string {
104 if e == nil {
105 return "<nil>"
106 }
107
108 if e.Container == nil {
109 return "unexpected nil container for error: " + e.Err.Error()
110 }
111
112 s := "container " + e.Container.system.ID()
113
114 if e.Operation != "" {
115 s += " encountered an error during " + e.Operation
116 }
117
118 switch e.Err.(type) {
119 case nil:
120 break
121 case syscall.Errno:
122 s += fmt.Sprintf(": failure in a Windows system call: %s (0x%x)", e.Err, hcserror.Win32FromError(e.Err))
123 default:
124 s += fmt.Sprintf(": %s", e.Err.Error())
125 }
126
127 for _, ev := range e.Events {
128 s += "\n" + ev.String()
129 }
130
131 return s
132 }
133
134 func (e *ProcessError) Error() string {
135 if e == nil {
136 return "<nil>"
137 }
138
139 if e.Process == nil {
140 return "Unexpected nil process for error: " + e.Err.Error()
141 }
142
143 s := fmt.Sprintf("process %d in container %s", e.Process.p.Pid(), e.Process.p.SystemID())
144 if e.Operation != "" {
145 s += " encountered an error during " + e.Operation
146 }
147
148 switch e.Err.(type) {
149 case nil:
150 break
151 case syscall.Errno:
152 s += fmt.Sprintf(": failure in a Windows system call: %s (0x%x)", e.Err, hcserror.Win32FromError(e.Err))
153 default:
154 s += fmt.Sprintf(": %s", e.Err.Error())
155 }
156
157 for _, ev := range e.Events {
158 s += "\n" + ev.String()
159 }
160
161 return s
162 }
163
164
165
166
167
168 func IsNotExist(err error) bool {
169 if _, ok := err.(EndpointNotFoundError); ok {
170 return true
171 }
172 if _, ok := err.(NetworkNotFoundError); ok {
173 return true
174 }
175 return hcs.IsNotExist(getInnerError(err))
176 }
177
178
179
180 func IsAlreadyClosed(err error) bool {
181 return hcs.IsAlreadyClosed(getInnerError(err))
182 }
183
184
185
186 func IsPending(err error) bool {
187 return hcs.IsPending(getInnerError(err))
188 }
189
190
191
192 func IsTimeout(err error) bool {
193 return hcs.IsTimeout(getInnerError(err))
194 }
195
196
197
198
199
200
201 func IsAlreadyStopped(err error) bool {
202 return hcs.IsAlreadyStopped(getInnerError(err))
203 }
204
205
206
207
208
209
210 func IsNotSupported(err error) bool {
211 return hcs.IsNotSupported(getInnerError(err))
212 }
213
214
215
216 func IsOperationInvalidState(err error) bool {
217 return hcs.IsOperationInvalidState(getInnerError(err))
218 }
219
220
221
222 func IsAccessIsDenied(err error) bool {
223 return hcs.IsAccessIsDenied(getInnerError(err))
224 }
225
226 func getInnerError(err error) error {
227 switch pe := err.(type) {
228 case nil:
229 return nil
230 case *ContainerError:
231 err = pe.Err
232 case *ProcessError:
233 err = pe.Err
234 }
235 return err
236 }
237
238 func convertSystemError(err error, c *container) error {
239 if serr, ok := err.(*hcs.SystemError); ok {
240 return &ContainerError{Container: c, Operation: serr.Op, Err: serr.Err, Events: serr.Events}
241 }
242 return err
243 }
244
245 func convertProcessError(err error, p *process) error {
246 if perr, ok := err.(*hcs.ProcessError); ok {
247 return &ProcessError{Process: p, Operation: perr.Op, Err: perr.Err, Events: perr.Events}
248 }
249 return err
250 }
251
View as plain text