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	"fmt"
14)
15
16// System datastore error codes
17
18func NewSystemDatastoreError(e error, msg string) Error {
19	return &err{level: EXCEPTION, ICode: 11000, IKey: "datastore.system.generic_error", ICause: e,
20		InternalMsg: "System datastore error " + msg, InternalCaller: CallerN(1)}
21
22}
23
24// Error code 11011 is retired. Do not reuse.
25
26func NewSystemKeyspaceNotFoundError(e error, msg string) Error {
27	return &err{level: EXCEPTION, ICode: 11002, IKey: "datastore.system.keyspace_not_found", ICause: e,
28		InternalMsg: "Keyspace not found " + msg, InternalCaller: CallerN(1)}
29
30}
31
32func NewSystemNotImplementedError(e error, msg string) Error {
33	return &err{level: EXCEPTION, ICode: 11003, IKey: "datastore.system.not_implemented", ICause: e,
34		InternalMsg: "System datastore :  Not implemented " + msg, InternalCaller: CallerN(1)}
35
36}
37
38func NewSystemNotSupportedError(e error, msg string) Error {
39	return &err{level: EXCEPTION, ICode: 11004, IKey: "datastore.system.not_supported", ICause: e,
40		InternalMsg: "System datastore : Not supported " + msg, InternalCaller: CallerN(1)}
41
42}
43
44func NewSystemIdxNotFoundError(e error, msg string) Error {
45	return &err{level: EXCEPTION, ICode: 11005, IKey: "datastore.system.idx_not_found", ICause: e,
46		InternalMsg: "System datastore : Index not found " + msg, InternalCaller: CallerN(1)}
47
48}
49
50func NewSystemIdxNoDropError(e error, msg string) Error {
51	return &err{level: EXCEPTION, ICode: 11006, IKey: "datastore.system.idx_no_drop", ICause: e,
52		InternalMsg: "System datastore : This  index cannot be dropped " + msg, InternalCaller: CallerN(1)}
53}
54
55func NewSystemStmtNotFoundError(e error, msg string) Error {
56	return &err{level: EXCEPTION, ICode: 11007, IKey: "datastore.system.stmt_not_found", ICause: e,
57		InternalMsg: "System datastore : Statement not found " + msg, InternalCaller: CallerN(1)}
58}
59
60func NewSystemRemoteWarning(e error, op string, ks string) Error {
61	return &err{level: WARNING, ICode: 11008, IKey: "datastore.system.remote_warning", ICause: e,
62		InternalMsg: "System datastore : " + op + " on " + ks + " failed", InternalCaller: CallerN(1)}
63}
64
65func NewSystemUnableToRetrieveError(e error) Error {
66	return &err{level: EXCEPTION, ICode: 11009, IKey: "datastore.system.unable_to_retrieve", ICause: e,
67		InternalMsg: "System datastore : unable to retrieve user roles from server", InternalCaller: CallerN(1), retry: true}
68}
69
70func NewSystemUnableToUpdateError(e error) Error {
71	return &err{level: EXCEPTION, ICode: 11010, IKey: "datastore.system.unable_to_update", ICause: e,
72		InternalMsg: "System datastore : unable to update user information in server", InternalCaller: CallerN(1)}
73}
74
75func NewSystemFilteredRowsWarning(keyspace string) Error {
76	return &err{level: WARNING, ICode: 11011, IKey: "datastore.system.filtered_keyspaces", onceOnly: true,
77		InternalMsg: fmt.Sprintf("One or more documents were excluded from the %s bucket because of insufficient user permissions. "+
78			"In an EE system, add the query_system_catalog role to see all rows. In a CE system, add the administrator role to see all rows.", keyspace),
79		InternalCaller: CallerN(1)}
80}
81
82func NewSystemMalformedKeyError(key string, keyspace string) Error {
83	return &err{level: EXCEPTION, ICode: 11012, IKey: "datastore.system.malformed_key",
84		InternalMsg:    fmt.Sprintf("System datastore : key %q is not of the correct format for keyspace %s", key, keyspace),
85		InternalCaller: CallerN(1)}
86}
87
88func NewSystemNoBuckets() Error {
89	return &err{level: EXCEPTION, ICode: 11013, IKey: "datastore.system.no_buckets",
90		InternalMsg:    "The system namespace contains no buckets that contain scopes.",
91		InternalCaller: CallerN(1)}
92}
93