forked from couchbase/indexing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
155 lines (132 loc) · 3.53 KB
/
error.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
154
155
// Copyright (c) 2014 Couchbase, Inc.
// 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 manager
import (
"fmt"
)
// The error handling has the same setup as the indexer.
// This is to help with consolidation on a common error facility
// at a later point.
type errCode int16
const (
// generic (0 - 50)
ERROR_PANIC errCode = 0
ERROR_ARGUMENTS = 1
// MetadataRepo (51-100)
ERROR_META_WRONG_KEY = 51
ERROR_META_IDX_DEFN_EXIST = 52
ERROR_META_IDX_DEFN_NOT_EXIST = 53
ERROR_META_FAIL_TO_PARSE_INT = 54
// Event Manager (101-150)
ERROR_EVT_DUPLICATE_NOTIFIER = 101
// Index Manager (151-200)
ERROR_MGR_DDL_CREATE_IDX = 151
ERROR_MGR_DDL_DROP_IDX = 152
// Coordinator (201-250)
ERROR_COOR_LISTENER_FAIL = 201
ERROR_COOR_ELECTION_FAIL = 202
// Watcher (251 - 300)
ERROR_WATCH_NO_ADDR_AVAIL = 251
// Stream (301-350)
ERROR_STREAM_INVALID_ARGUMENT = 301
ERROR_STREAM_NOT_OPEN = 302
ERROR_STREAM_REQUEST_ERROR = 303
ERROR_STREAM_WRONG_VBUCKET = 304
ERROR_STREAM_INVALID_TIMESTAMP = 305
ERROR_STREAM_PROJECTOR_TIMEOUT = 306
ERROR_STREAM_INVALID_KVADDRS = 307
ERROR_STREAM_STREAM_END = 308
ERROR_STREAM_FEEDER = 309
ERROR_STREAM_INCONSISTENT_VBMAP = 310
)
type errSeverity int16
const (
FATAL errSeverity = iota
NORMAL
)
type errCategory int16
const (
GENERIC errCategory = iota
COORDINATOR
INDEX_MANAGER
METADATA_REPO
REQUEST_HANDLER
EVENT_MANAGER
WATCHER
STREAM
)
type Error struct {
code errCode
severity errSeverity
category errCategory
cause error
msg string
}
func NewError(code errCode, severity errSeverity, category errCategory, cause error, msg string) Error {
return Error{code: code,
severity: severity,
category: category,
cause: cause,
msg: msg}
}
func NewError4(code errCode, severity errSeverity, category errCategory, msg string) Error {
return Error{code: code,
severity: severity,
category: category,
cause: nil,
msg: msg}
}
func NewError3(code errCode, severity errSeverity, category errCategory) Error {
return Error{code: code,
severity: severity,
category: category,
cause: nil,
msg: ""}
}
func NewError2(code errCode, category errCategory) Error {
return Error{code: code,
severity: NORMAL,
category: category,
cause: nil,
msg: ""}
}
func (e Error) Error() string {
return fmt.Sprintf("Error :: code= %d, severity= %s, category= %s, reason= %s, cause= %s",
e.code, severity(e.severity), category(e.category), e.msg, e.cause)
}
func category(category errCategory) string {
switch category {
case GENERIC:
return "Generic"
case COORDINATOR:
return "Coordinator"
case INDEX_MANAGER:
return "Index Manager"
case METADATA_REPO:
return "Metadata Repo"
case REQUEST_HANDLER:
return "Request Handler"
case EVENT_MANAGER:
return "Event Manager"
case WATCHER:
return "Watcher"
case STREAM:
return "Stream"
}
return ""
}
func severity(severity errSeverity) string {
switch severity {
case NORMAL:
return "Normal"
case FATAL:
return "Fatal"
}
return ""
}