-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
77 lines (61 loc) · 1.62 KB
/
error.go
File metadata and controls
77 lines (61 loc) · 1.62 KB
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
package main
import "fmt"
type SVError struct {
Message string
Type string
}
func (e *SVError) Error() string {
return e.Message
}
func NewError(msg string) error {
return &SVError{Message: msg, Type: "error"}
}
func NewWarning(msg string) error {
return &SVError{Message: msg, Type: "warning"}
}
func NewInfo(msg string) error {
return &SVError{Message: msg, Type: "info"}
}
func ErrTagEmpty() error {
return NewError("tag is empty")
}
func ErrURLEmpty() error {
return NewError("download URL is empty")
}
func ErrLocalNotExist() error {
return NewInfo("local version does not exist")
}
func ErrVersionInUse(version string) error {
return NewWarning(fmt.Sprintf("version %s is in use, please switch to another version before uninstalling", version))
}
func ErrNoVersionsAvailable() error {
return NewInfo("no available versions locally to select, you can use -r for remote versions")
}
func ErrLatestVersionFailed() error {
return NewError("get latest version information failed, please try again")
}
func ErrAlreadyLatest(version string) error {
return NewInfo(fmt.Sprintf("you already have the latest version of SV (%s)", version))
}
func ErrChecksumMismatch() error {
return NewError("file checksum does not match, file may be corrupted")
}
func ErrUnsupportedCommand() error {
return NewError("unsupported command")
}
func PrintError(err error) {
if svErr, ok := err.(*SVError); ok {
switch svErr.Type {
case "error":
PrintRed(svErr.Message)
case "warning":
PrintYellow(svErr.Message)
case "info":
PrintBlue(svErr.Message)
default:
PrintRed(svErr.Message)
}
} else {
PrintRed(err.Error())
}
}