-
Notifications
You must be signed in to change notification settings - Fork 7
/
errors.go
66 lines (53 loc) · 1.48 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
package hcs
import (
"fmt"
"syscall"
"github.com/Microsoft/hcsshim"
)
type NotFoundError struct {
Id string
}
func (e *NotFoundError) Error() string {
return fmt.Sprintf("container not found: %s", e.Id)
}
type DuplicateError struct {
Id string
}
func (e *DuplicateError) Error() string {
return fmt.Sprintf("multiple containers found with the same id: %s", e.Id)
}
type LowMemoryError struct{}
func (e *LowMemoryError) Error() string {
return fmt.Sprintf("not enough memory")
}
func CleanError(err error) error {
cErr, ok := err.(*hcsshim.ContainerError)
if !ok {
return err
}
errno, ok := cErr.Err.(syscall.Errno)
if !ok {
return cErr.Err
}
// following list of errors generated by running this code in a low memory
// environment several times
//
// actually an OOM error:
// 0x5af is ERROR_COMMITMENT_LIMIT
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms681385(v=vs.85).aspx
//
// not directly an OOM error but show up in testing:
// 0x6be is RPC_S_CALL_FAILED
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms681386(v=vs.85).aspx
// 0x71a is ERROR_COMMITMENT_LIMIT
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms681386(v=vs.85).aspx
// 0x36b1 is ERROR_SXS_CANT_GEN_ACTCTX
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms681384(v=vs.85).aspx
oomCodes := []syscall.Errno{0x5af, 0x6be, 0x71a, 0x36b1}
for _, code := range oomCodes {
if errno == code {
return &LowMemoryError{}
}
}
return cErr.Err
}