1//  Copyright (c) 2014 Couchbase, Inc.
2//  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
3//  except in compliance with the License. You may obtain a copy of the License at
4//    http://www.apache.org/licenses/LICENSE-2.0
5//  Unless required by applicable law or agreed to in writing, software distributed under the
6//  License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
7//  either express or implied. See the License for the specific language governing permissions
8//  and limitations under the License.
9
10package errors
11
12import ()
13
14// Datastore/couchbase error codes
15func NewCbConnectionError(e error, msg string) Error {
16	return &err{level: EXCEPTION, ICode: 12000, IKey: "datastore.couchbase.connection_error", ICause: e,
17		InternalMsg: "Cannot connect " + msg, InternalCaller: CallerN(1)}
18
19}
20
21// Error code 12001 is retired. Do not reuse.
22
23func NewCbNamespaceNotFoundError(e error, msg string) Error {
24	return &err{level: EXCEPTION, ICode: 12002, IKey: "datastore.couchbase.namespace_not_found", ICause: e,
25		InternalMsg: "Namespace not found in CB datastore " + msg, InternalCaller: CallerN(1)}
26}
27
28func NewCbKeyspaceNotFoundError(e error, msg string) Error {
29	return &err{level: EXCEPTION, ICode: 12003, IKey: "datastore.couchbase.keyspace_not_found", ICause: e,
30		InternalMsg: "Keyspace not found in CB datastore " + msg, InternalCaller: CallerN(1)}
31}
32
33func NewCbPrimaryIndexNotFoundError(e error, msg string) Error {
34	return &err{level: EXCEPTION, ICode: 12004, IKey: "datastore.couchbase.primary_idx_not_found", ICause: e,
35		InternalMsg: "Primary Index not found " + msg, InternalCaller: CallerN(1)}
36}
37
38func NewCbIndexerNotImplementedError(e error, msg string) Error {
39	return &err{level: EXCEPTION, ICode: 12005, IKey: "datastore.couchbase.indexer_not_implemented", ICause: e,
40		InternalMsg: "Indexer not implemented " + msg, InternalCaller: CallerN(1)}
41}
42
43func NewCbKeyspaceCountError(e error, msg string) Error {
44	return &err{level: EXCEPTION, ICode: 12006, IKey: "datastore.couchbase.keyspace_count_error", ICause: e,
45		InternalMsg: "Failed to get keyspace count " + msg, InternalCaller: CallerN(1), retry: true}
46}
47
48// Error code 12007 is retired. Do not reuse.
49
50func NewCbBulkGetError(e error, msg string) Error {
51	return &err{level: EXCEPTION, ICode: 12008, IKey: "datastore.couchbase.bulk_get_error", ICause: e,
52		InternalMsg: "Error performing bulk get operation " + msg, InternalCaller: CallerN(1), retry: true}
53}
54
55func NewCbDMLError(e error, msg string) Error {
56	return &err{level: EXCEPTION, ICode: 12009, IKey: "datastore.couchbase.DML_error", ICause: e,
57		InternalMsg: "DML Error, possible causes include CAS mismatch or concurrent modification" + msg, InternalCaller: CallerN(1)}
58}
59
60// Error code 12010 is retired. Do not reuse.
61
62func NewCbDeleteFailedError(e error, msg string) Error {
63	return &err{level: EXCEPTION, ICode: 12011, IKey: "datastore.couchbase.delete_failed", ICause: e,
64		InternalMsg: msg, InternalCaller: CallerN(1)}
65}
66
67func NewCbLoadIndexesError(e error, msg string) Error {
68	return &err{level: EXCEPTION, ICode: 12012, IKey: "datastore.couchbase.load_index_failed", ICause: e,
69		InternalMsg: "Failed to load indexes " + msg, InternalCaller: CallerN(1)}
70}
71
72func NewCbBucketTypeNotSupportedError(e error, msg string) Error {
73	return &err{level: EXCEPTION, ICode: 12013, IKey: "datastore.couchbase.bucket_type_not_supported", ICause: e,
74		InternalMsg: "This bucket type is not supported " + msg, InternalCaller: CallerN(1)}
75}
76
77// Error code 12014 is retired. Do not reuse.
78
79const INDEX_SCAN_TIMEOUT = 12015
80
81func NewCbIndexScanTimeoutError(e error) Error {
82	return &err{level: EXCEPTION, ICode: INDEX_SCAN_TIMEOUT, IKey: "datastore.couchbase.index_scan_timeout", ICause: e,
83		InternalMsg: "Index scan timed out", InternalCaller: CallerN(1)}
84}
85
86const INDEX_NOT_FOUND = 12016
87
88func NewCbIndexNotFoundError(e error) Error {
89	return &err{level: EXCEPTION, ICode: INDEX_NOT_FOUND, IKey: "datastore.couchbase.index_not_found", ICause: e,
90		InternalMsg: "Index Not Found", InternalCaller: CallerN(1), retry: true}
91}
92
93const GET_RANDOM_ENTRY_ERROR = 12017
94
95func NewCbGetRandomEntryError(e error) Error {
96	return &err{level: EXCEPTION, ICode: GET_RANDOM_ENTRY_ERROR, IKey: "datastore.couchbase.get_random_entry_error", ICause: e,
97		InternalMsg: "Error getting random entry from keyspace", InternalCaller: CallerN(1)}
98}
99
100func NewUnableToInitCbAuthError(e error) Error {
101	return &err{level: EXCEPTION, ICode: 12018, IKey: "datastore.couchbase.unable_to_init_cbauth_error", ICause: e,
102		InternalMsg: "Unable to initialize authorization system as required", InternalCaller: CallerN(1)}
103}
104
105func NewAuditStreamHandlerFailed(e error) Error {
106	return &err{level: EXCEPTION, ICode: 12019, IKey: "datastore.couchbase.audit_stream_failed event id", ICause: e,
107		InternalMsg: "Audit stream handler failed", InternalCaller: CallerN(1)}
108}
109
110func NewCbBucketNotFoundError(e error, msg string) Error {
111	return &err{level: EXCEPTION, ICode: 12020, IKey: "datastore.couchbase.bucket_not_found", ICause: e,
112		InternalMsg: "Bucket not found in CB datastore " + msg, InternalCaller: CallerN(1)}
113}
114
115func NewCbScopeNotFoundError(e error, msg string) Error {
116	return &err{level: EXCEPTION, ICode: 12021, IKey: "datastore.couchbase.scope_not_found", ICause: e,
117		InternalMsg: "Scope not found in CB datastore " + msg, InternalCaller: CallerN(1)}
118}
119
120func NewCbKeyspaceSizeError(e error, msg string) Error {
121	return &err{level: EXCEPTION, ICode: 12022, IKey: "datastore.couchbase.keyspace_size_error", ICause: e,
122		InternalMsg: "Failed to get keyspace size " + msg, InternalCaller: CallerN(1), retry: true}
123}
124
125func NewCbSecurityConfigNotProvided(bucket string) Error {
126	return &err{level: EXCEPTION, ICode: 12023, IKey: "datastore.couchbase.security_config_not_provided",
127		InternalMsg: "Connection security config not provided. Unable to load bucket " + bucket, InternalCaller: CallerN(1), retry: true}
128}
129