forked from hyperhq/runv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
73 lines (61 loc) · 1.45 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
package hypervisor
const (
ET_SPEC string = "SPEC_ERROR"
ET_BUSY string = "RESOURSE_UNAVAILABLE"
ET_DEVICE string = "DEVICE_OPERATION_FAIL"
ET_NOT_READY string = "VM_NOT_READY"
)
type Errors interface {
Type() string
}
//implement error, hypervisor.Error, and api.Result
type CommonError struct {
errType string
contextId string
cause string
}
func (err *CommonError) Error() string {
return err.cause
}
func (err *CommonError) Type() string {
return err.errType
}
func (err *CommonError) ResultId() string {
return err.contextId
}
func (err *CommonError) IsSuccess() bool {
return false
}
func (err *CommonError) Message() string {
return err.cause
}
// Error in spec, which is either mistake format or content inconsistency, and
// is checked when elements are being added to Sandbox.
func NewSpecError(id, cause string) *CommonError {
return &CommonError{
errType: ET_SPEC,
contextId: id,
cause: "spec error: " + cause,
}
}
func NewBusyError(id, cause string) *CommonError {
return &CommonError{
errType: ET_BUSY,
contextId: id,
cause: "resouse unavailable: " + cause,
}
}
func NewDeviceError(id, cause string) *CommonError {
return &CommonError{
errType: ET_DEVICE,
contextId: id,
cause: "device operation error: " + cause,
}
}
func NewNotReadyError(id string) *CommonError {
return &CommonError{
errType: ET_NOT_READY,
contextId: id,
cause: "vm is not ready to accept requests",
}
}