generated from brevdev/seed
-
Notifications
You must be signed in to change notification settings - Fork 9
/
errors.go
136 lines (97 loc) · 3.1 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package errors
import (
"fmt"
"runtime"
"github.com/pkg/errors"
)
type BrevError interface {
// Error returns a user-facing string explaining the error
Error() string
// Directive returns a user-facing string explaining how to overcome the error
Directive() string
}
type SuppressedError struct{}
func (e *SuppressedError) Directive() string {
return ""
}
func (e *SuppressedError) Error() string {
return ""
}
type CredentialsFileNotFound struct{}
func (e *CredentialsFileNotFound) Directive() string {
return "run `brev login`"
}
func (e *CredentialsFileNotFound) Error() string {
return "credentials file not found"
}
type ActiveOrgFileNotFound struct{}
func (e *ActiveOrgFileNotFound) Directive() string {
return "run `brev set`"
}
func (e *ActiveOrgFileNotFound) Error() string {
return "active org is not set"
}
type LocalProjectFileNotFound struct{}
func (e *LocalProjectFileNotFound) Directive() string {
return "run `brev init`"
}
func (e *LocalProjectFileNotFound) Error() string {
return "local project file not found"
}
type LocalEndpointFileNotFound struct{}
func (e *LocalEndpointFileNotFound) Directive() string {
return "run `brev init`"
}
func (e *LocalEndpointFileNotFound) Error() string {
return "local endpoint file not found"
}
type InitExistingProjectFile struct{}
func (e *InitExistingProjectFile) Directive() string {
return "move to a new directory or delete the local .brev directory"
}
func (e *InitExistingProjectFile) Error() string {
return "`brev init` called in a directory with an existing project file"
}
type InitExistingEndpointsFile struct{}
func (e *InitExistingEndpointsFile) Directive() string {
return "move to a new directory or delete the local .brev directory"
}
func (e *InitExistingEndpointsFile) Error() string {
return "init called in a directory with an existing endpoints file"
}
type CotterClientError struct{}
func (e *CotterClientError) Directive() string {
return "run `brev login`"
}
func (e *CotterClientError) Error() string {
return "invalid refresh token reported by auth server"
}
type CotterServerError struct{}
func (e *CotterServerError) Directive() string {
return "wait for 60 seconds and run `brev login`"
}
func (e *CotterServerError) Error() string {
return "internal error reported by auth server"
}
type InvalidOrganizationError struct{}
func (e *InvalidOrganizationError) Directive() string {
return "please use a valid organization."
}
func (e *InvalidOrganizationError) Error() string {
return "invalid organization"
}
type DeclineToLoginError struct{}
func (d *DeclineToLoginError) Error() string { return "declined to login" }
func (d *DeclineToLoginError) Directive() string { return "log in to run this command" }
func WrapAndTrace(err error, messages ...string) error {
message := ""
for _, m := range messages {
message += fmt.Sprintf(" %s", m)
}
return errors.Wrap(err, MakeErrorMessage(message))
}
func MakeErrorMessage(message string) string {
_, fn, line, _ := runtime.Caller(2)
return fmt.Sprintf("[error] %s:%d %s\n\t", fn, line, message)
}
var NetworkErrorMessage = "possible internet connection problem"