-
Notifications
You must be signed in to change notification settings - Fork 2
/
errors.go
56 lines (44 loc) · 1.21 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
package vcon
import (
"context"
"fmt"
"time"
)
// ErrorCoder gives errors a code to return with os.Exit
type ErrorCoder interface {
// Code provides the integer error code to return
Code() int
}
// ConnectionError occurs when vcon fails to establish a connection to vSphere
// or the user has not provided a valid datacenter or datastore name
type ConnectionError struct{}
func (ce ConnectionError) Error() string {
return "Failed to connect to vSphere"
}
func (ce ConnectionError) Code() int {
return 1
}
type NotFoundError struct {
Path string
}
func (nfe NotFoundError) Error() string {
return fmt.Sprintf("Failed to find VM identified by '%s'", nfe.Path)
}
func (nfe NotFoundError) Code() int {
return 2
}
// TimeoutExceededError occurs when a collection of vSphere operations does
// not complete in the determined timeout
type TimeoutExceededError struct {
timeout time.Duration
}
func (tee TimeoutExceededError) Error() string {
return fmt.Sprintf("Timed out after %d seconds", tee.timeout)
}
// Cause returns the root cause, which will always be context.DeadlineExceeded
func (tee TimeoutExceededError) Cause() error {
return context.DeadlineExceeded
}
func (tee TimeoutExceededError) Code() int {
return 3
}