forked from rakyll/drive
-
Notifications
You must be signed in to change notification settings - Fork 427
/
errors.go
153 lines (126 loc) · 4.13 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Copyright 2016 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package drive
type ErrorStatus int
const (
StatusGeneric ErrorStatus = 1
StatusAuthenticationFailed ErrorStatus = 2
StatusRetriesExhausted ErrorStatus = 3
StatusDownloadFailed ErrorStatus = 4
StatusPullFailed ErrorStatus = 5
StatusGoogleDocNonExportAttempted ErrorStatus = 6
StatusInvalidGoogleAPIQuery ErrorStatus = 7
StatusIllogicalState ErrorStatus = 8
StatusNonExistantRemote ErrorStatus = 9
StatusRemoteLookupFailed ErrorStatus = 10
StatusLocalLookupFailed ErrorStatus = 11
StatusNetLookupFailed ErrorStatus = 12
StatusClashesDetected ErrorStatus = 13
StatusClashFixingAborted ErrorStatus = 14
StatusMkdirFailed ErrorStatus = 15
StatusNoMatchesFound ErrorStatus = 16
StatusUnresolvedConflicts ErrorStatus = 17
StatusCannotPrompt ErrorStatus = 18
StatusOverwriteAttempted ErrorStatus = 19
StatusImmutableOperationAttempted ErrorStatus = 20
StatusInvalidArguments ErrorStatus = 21
StatusNamedPipeReadAttempt ErrorStatus = 22
StatusContentTooLarge ErrorStatus = 23
)
type Error struct {
code ErrorStatus
status string
err error
}
func (e Error) Error() string {
joins := []string{}
if e.status != "" {
joins = append(joins, e.status)
}
if e.err != nil {
joins = append(joins, e.err.Error())
}
return sepJoin(" ", joins...)
}
func (e Error) Code() int {
return int(e.code)
}
func makeError(err error, code ErrorStatus) *Error {
return &Error{
code: code,
err: err,
}
}
func makeErrorWithStatus(status string, err error, code ErrorStatus) *Error {
e := makeError(err, code)
e.status = status
return e
}
func googleDocNonExportErr(err error) *Error {
return makeError(err, StatusGoogleDocNonExportAttempted)
}
func downloadFailedErr(err error) *Error {
return makeError(err, StatusDownloadFailed)
}
func illogicalStateErr(err error) *Error {
return makeError(err, StatusIllogicalState)
}
func invalidGoogleAPIQueryErr(err error) *Error {
return makeError(err, StatusInvalidGoogleAPIQuery)
}
func nonExistantRemoteErr(err error) *Error {
return makeError(err, StatusNonExistantRemote)
}
func netLookupFailedErr(err error) *Error {
return makeError(err, StatusNetLookupFailed)
}
func clashesDetectedErr(err error) *Error {
return makeError(err, StatusClashesDetected)
}
func clashFixingAbortedErr(err error) *Error {
return makeError(err, StatusClashFixingAborted)
}
func mkdirFailedErr(err error) *Error {
return makeError(err, StatusMkdirFailed)
}
func noMatchesFoundErr(err error) *Error {
return makeError(err, StatusNoMatchesFound)
}
func unresolvedConflictsErr(err error) *Error {
return makeError(err, StatusUnresolvedConflicts)
}
func pullFailedErr(err error) *Error {
return makeError(err, StatusPullFailed)
}
func cannotPromptErr(err error) *Error {
return makeError(err, StatusCannotPrompt)
}
func overwriteAttemptedErr(err error) *Error {
return makeError(err, StatusOverwriteAttempted)
}
func immutableAttemptErr(err error) *Error {
return makeError(err, StatusImmutableOperationAttempted)
}
func remoteLookupErr(err error) *Error {
return makeError(err, StatusRemoteLookupFailed)
}
func invalidArgumentsErr(err error) *Error {
return makeError(err, StatusInvalidArguments)
}
func namedPipeReadAttemptErr(err error) *Error {
return makeError(err, StatusNamedPipeReadAttempt)
}
func contentTooLargeErr(err error) *Error {
return makeError(err, StatusContentTooLarge)
}