-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patherrors.go
93 lines (76 loc) · 2.3 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
package vm
import (
"fmt"
"os"
"github.com/libvirt/libvirt-go"
)
// A MissingPositionalArgErr occurs when a command is invoked without a required
// positional argument.
type MissingPositionalArgErr struct {
name string
}
func (e MissingPositionalArgErr) Error() string {
return fmt.Sprintf("error: %v is required", e.name)
}
// ErrDomainNameRequired represents a missing domain name argument.
var ErrDomainNameRequired = MissingPositionalArgErr{
name: "domain name",
}
// ErrImageNameRequired represents a missing image name argument.
var ErrImageNameRequired = MissingPositionalArgErr{
name: "image name",
}
// ErrTemplateNameRequired represents a missing template name argument.
var ErrTemplateNameRequired = MissingPositionalArgErr{
name: "template name",
}
// ErrURLOrPathRequired represents a missing URL or path argument.
var ErrURLOrPathRequired = MissingPositionalArgErr{
name: "URL or path",
}
// An InvalidArgumentErr occurs when a value passed to an argument is invalid.
type InvalidArgumentErr struct {
name string
err error
}
func (e InvalidArgumentErr) Error() string {
return "error: invalid argument: " + e.name + ": " + e.err.Error()
}
// An UnsupportedFormatErr occurs when a command is invoked that does not
// support the specified format.
type UnsupportedFormatErr struct {
format string
}
func (e UnsupportedFormatErr) Error() string {
return "error: unsupported format: " + e.format
}
// ErrUnsupportedJSONFormat represents a command requesting JSON when it is
// not supported.
var ErrUnsupportedJSONFormat = UnsupportedFormatErr{
format: "JSON",
}
// ErrUnsupportedXMLFormat represents a command requesting XML when it is
// not supported.
var ErrUnsupportedXMLFormat = UnsupportedFormatErr{
format: "XML",
}
// UnsupportedDomainCapabilityErr occurs when a domain capability is not
// supported on the host.
type UnsupportedDomainCapabilityErr struct {
capability string
}
func (e UnsupportedDomainCapabilityErr) Error() string {
return "error: domain capability not supported: " + e.capability
}
// LogErrorAndExit logs err and exits with a non-zero exit code.
func LogErrorAndExit(err error) {
switch err.(type) {
case libvirt.Error:
e := err.(libvirt.Error)
fmt.Fprintf(os.Stderr, "%v\n", e.Message)
os.Exit(int(e.Code))
default:
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}