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// Shell errors -- errors in the command line shell
15
16const (
17	//Connection errors (100 - 115)
18	CONNECTION_REFUSED       = 100
19	CONNECTION_REFUSED_MSG   = ""
20	UNSUPPORTED_PROTOCOL     = 101
21	UNSUPPORTED_PROTOCOL_MSG = "Unsupported protocol scheme "
22	NO_SUCH_HOST             = 102
23	NO_SUCH_HOST_MSG         = "No such host "
24	NO_HOST_IN_URL           = 103
25	NO_HOST_IN_URL_MSG       = "No host in request URL "
26	UNKNOWN_PORT_TCP         = 104
27	UNKNOWN_PORT_TCP_MSG     = "Unknown port "
28	NO_ROUTE_TO_HOST         = 105
29	NO_ROUTE_TO_HOST_MSG     = "No route to host "
30	UNREACHABLE_NETWORK      = 106
31	UNREACHABLE_NETWORK_MSG  = "Network is unreachable."
32	NO_CONNECTION            = 107
33	NO_CONNECTION_MSG        = "Not connected to any cluster. Use \\CONNECT command."
34	DRIVER_OPEN              = 108
35	DRIVER_OPEN_MSG          = ""
36	INVALID_URL              = 109
37	INVALID_URL_MSG          = "Invalid input URL "
38
39	//Read/Write/Update file errors (116 - 120)
40	READ_FILE      = 116
41	READ_FILE_MSG  = "Error during file read "
42	WRITE_FILE     = 117
43	WRITE_FILE_MSG = "Error during file write "
44	FILE_OPEN      = 118
45	FILE_OPEN_MSG  = "Unable to open file "
46	FILE_CLOSE     = 119
47	FILE_CLOSE_MSG = "Unable to close file "
48
49	//Authentication Errors (121 - 135)
50	//Missing or invalid username/password.
51	INVALID_PASSWORD       = 121
52	INVALID_PASSWORD_MSG   = "Invalid password "
53	INVALID_USERNAME       = 122
54	INVALID_USERNAME_MSG   = "Invalid username. "
55	MISSING_CREDENTIAL     = 123
56	MISSING_CREDENTIAL_MSG = "Username missing in -credentials/-c option."
57	INVALID_CREDENTIAL     = 124
58	INVALID_CREDENTIAL_MSG = "Invalid format for credentials. Separate username and password by a :. "
59
60	//Command Errors (136 - 169)
61	NO_SUCH_COMMAND     = 136
62	NO_SUCH_COMMAND_MSG = "Command does not exist."
63	NO_SUCH_PARAM       = 137
64	NO_SUCH_PARAM_MSG   = "Parameter does not exist "
65	TOO_MANY_ARGS       = 138
66	TOO_MANY_ARGS_MSG   = "Too many input arguments to command."
67	TOO_FEW_ARGS        = 139
68	TOO_FEW_ARGS_MSG    = "Too few input arguments to command."
69	STACK_EMPTY         = 140
70	STACK_EMPTY_MSG     = "Stack empty."
71	NO_SUCH_ALIAS       = 141
72	NO_SUCH_ALIAS_MSG   = "Alias does not exist "
73	BATCH_MODE          = 142
74	BATCH_MODE_MSG      = "Error when running in batch mode for Analytics. Incorrect input value"
75	STRING_WRITE        = 143
76	STRING_WRITE_MSG    = "Cannot write to string buffer. "
77
78	//Generic Errors (170 - 199)
79	OPERATION_TIMEOUT           = 170
80	OPERATION_TIMEOUT_MSG       = "Operation timed out. Check query service url "
81	ROWS_SCAN                   = 171
82	ROWS_SCAN_MSG               = ""
83	JSON_MARSHAL                = 172
84	JSON_MARSHAL_MSG            = ""
85	JSON_UNMARSHAL              = 173
86	JSON_UNMARSHAL_MSG          = ""
87	DRIVER_QUERY                = 174
88	DRIVER_QUERY_MSG            = ""
89	WRITER_OUTPUT               = 175
90	WRITER_OUTPUT_MSG           = "Error with io Writer. "
91	UNBALANCED_PAREN            = 176
92	UNBALANCED_PAREN_MSG        = "Unbalanced parenthesis in the input."
93	ROWS_CLOSE                  = 177
94	ROWS_CLOSE_MSG              = ""
95	CMD_LINE_ARG                = 178
96	CMD_LINE_ARG_MSG            = "Place input argument URL at the end, after input flags. "
97	INVALID_INPUT_ARGUMENTS     = 179
98	INVALID_INPUT_ARGUMENTS_MSG = "Input Argument format is invalid."
99
100	//Untracked error
101	UNKNOWN_ERROR     = 199
102	UNKNOWN_ERROR_MSG = ""
103)
104
105//Connection errors
106func NewShellErrorCannotConnect(msg string) Error {
107	return &err{level: EXCEPTION, ICode: CONNECTION_REFUSED, IKey: "shell.connection.refused", InternalMsg: CONNECTION_REFUSED_MSG + msg, InternalCaller: CallerN(1)}
108}
109
110func NewShellErrorUnsupportedProtocol(msg string) Error {
111	return &err{level: EXCEPTION, ICode: UNSUPPORTED_PROTOCOL, IKey: "shell.unsupported.protocol", InternalMsg: UNSUPPORTED_PROTOCOL_MSG + msg, InternalCaller: CallerN(1)}
112}
113
114func NewShellErrorNoSuchHost(msg string) Error {
115	return &err{level: EXCEPTION, ICode: NO_SUCH_HOST, IKey: "shell.no.such.host", InternalMsg: NO_SUCH_HOST_MSG + msg, InternalCaller: CallerN(1)}
116}
117
118func NewShellErrorNoHostInRequestUrl(msg string) Error {
119	return &err{level: EXCEPTION, ICode: NO_HOST_IN_URL, IKey: "shell.no.host.in.request.url", InternalMsg: NO_HOST_IN_URL_MSG + msg, InternalCaller: CallerN(1)}
120}
121
122func NewShellErrorUnknownPorttcp(msg string) Error {
123	return &err{level: EXCEPTION, ICode: UNKNOWN_PORT_TCP, IKey: "shell.unknown.port.tcp", InternalMsg: UNKNOWN_PORT_TCP_MSG + msg, InternalCaller: CallerN(1)}
124}
125
126func NewShellErrorNoRouteToHost(msg string) Error {
127	return &err{level: EXCEPTION, ICode: NO_ROUTE_TO_HOST, IKey: "shell.no.route.to.host", InternalMsg: NO_ROUTE_TO_HOST_MSG + msg, InternalCaller: CallerN(1)}
128}
129
130func NewShellErrorUnreachableNetwork(msg string) Error {
131	return &err{level: EXCEPTION, ICode: UNREACHABLE_NETWORK, IKey: "shell.unreachable.network", InternalMsg: UNREACHABLE_NETWORK_MSG + msg, InternalCaller: CallerN(1)}
132}
133
134func NewShellErrorNoConnection(msg string) Error {
135	return &err{level: EXCEPTION, ICode: NO_CONNECTION, IKey: "shell.not.connected.to.any.instance", InternalMsg: NO_CONNECTION_MSG + msg, InternalCaller: CallerN(1)}
136}
137
138func NewShellErrorDriverOpen(msg string) Error {
139	return &err{level: EXCEPTION, ICode: DRIVER_OPEN, IKey: "shell.driver.Open.method.error", InternalMsg: DRIVER_OPEN_MSG + msg, InternalCaller: CallerN(1)}
140}
141
142func NewShellErrorInvalidURL(msg string) Error {
143	return &err{level: EXCEPTION, ICode: INVALID_URL, IKey: "shell.Invalid.URL", InternalMsg: INVALID_URL_MSG + msg, InternalCaller: CallerN(1)}
144}
145
146//Read/Write/Update file errors
147func NewShellErrorReadFile(msg string) Error {
148	return &err{level: EXCEPTION, ICode: READ_FILE, IKey: "shell.read.history", InternalMsg: READ_FILE_MSG + msg, InternalCaller: CallerN(1)}
149}
150
151func NewShellErrorWriteFile(msg string) Error {
152	return &err{level: EXCEPTION, ICode: WRITE_FILE, IKey: "shell.write.history", InternalMsg: WRITE_FILE_MSG + msg, InternalCaller: CallerN(1)}
153}
154
155func NewShellErrorOpenFile(msg string) Error {
156	return &err{level: EXCEPTION, ICode: FILE_OPEN, IKey: "shell.unable.to.open.file", InternalMsg: FILE_OPEN_MSG + msg, InternalCaller: CallerN(1)}
157}
158
159func NewShellErrorCloseFile(msg string) Error {
160	return &err{level: EXCEPTION, ICode: FILE_CLOSE, IKey: "shell.unable.to.open.file", InternalMsg: FILE_CLOSE_MSG + msg, InternalCaller: CallerN(1)}
161}
162
163//Authentication Errors. Missing or invalid username/password.
164func NewShellErrorInvalidPassword(msg string) Error {
165	return &err{level: EXCEPTION, ICode: INVALID_PASSWORD, IKey: "shell.invalid.password", InternalMsg: INVALID_PASSWORD_MSG + msg, InternalCaller: CallerN(1)}
166}
167
168func NewShellErrorInvalidUsername(msg string) Error {
169	return &err{level: EXCEPTION, ICode: INVALID_USERNAME, IKey: "shell.invalid.username", InternalMsg: INVALID_USERNAME_MSG + msg, InternalCaller: CallerN(1)}
170}
171
172func NewShellErrorMissingCredential(msg string) Error {
173	return &err{level: EXCEPTION, ICode: MISSING_CREDENTIAL, IKey: "shell.missing.credentials", InternalMsg: MISSING_CREDENTIAL_MSG + msg, InternalCaller: CallerN(1)}
174
175}
176
177func NewShellErrorInvalidCredential(msg string) Error {
178	return &err{level: EXCEPTION, ICode: INVALID_CREDENTIAL, IKey: "shell.invalid.credentials", InternalMsg: INVALID_CREDENTIAL_MSG + msg, InternalCaller: CallerN(1)}
179
180}
181
182//Command Errors
183func NewShellErrorNoSuchCommand(msg string) Error {
184	return &err{level: EXCEPTION, ICode: NO_SUCH_COMMAND, IKey: "shell.no.such.command", InternalMsg: NO_SUCH_COMMAND_MSG + msg, InternalCaller: CallerN(1)}
185}
186
187func NewShellErrorNoSuchParam(msg string) Error {
188	return &err{level: EXCEPTION, ICode: NO_SUCH_PARAM, IKey: "shell.no.such.param", InternalMsg: NO_SUCH_PARAM_MSG + msg, InternalCaller: CallerN(1)}
189}
190
191func NewShellErrorTooManyArgs(msg string) Error {
192	return &err{level: EXCEPTION, ICode: TOO_MANY_ARGS, IKey: "shell.too.many.args", InternalMsg: TOO_MANY_ARGS_MSG + msg, InternalCaller: CallerN(1)}
193}
194
195func NewShellErrorTooFewArgs(msg string) Error {
196	return &err{level: EXCEPTION, ICode: TOO_FEW_ARGS, IKey: "shell.too.few.args", InternalMsg: TOO_FEW_ARGS_MSG + msg, InternalCaller: CallerN(1)}
197}
198
199func NewShellErrorStackEmpty(msg string) Error {
200	return &err{level: EXCEPTION, ICode: STACK_EMPTY, IKey: "shell.parameter.stack.empty", InternalMsg: STACK_EMPTY_MSG + msg, InternalCaller: CallerN(1)}
201
202}
203
204func NewShellErrorNoSuchAlias(msg string) Error {
205	return &err{level: EXCEPTION, ICode: NO_SUCH_ALIAS, IKey: "shell.alias.does.not.exist", InternalMsg: NO_SUCH_ALIAS_MSG + msg, InternalCaller: CallerN(1)}
206
207}
208
209func NewShellErrorBatchMode(msg string) Error {
210	return &err{level: EXCEPTION, ICode: BATCH_MODE, IKey: "batch.mode.incorrect.input", InternalMsg: BATCH_MODE_MSG + msg, InternalCaller: CallerN(1)}
211
212}
213
214func NewShellErrorStringWrite(msg string) Error {
215	return &err{level: EXCEPTION, ICode: STRING_WRITE, IKey: "string.buffer.write.error", InternalMsg: STRING_WRITE_MSG + msg, InternalCaller: CallerN(1)}
216
217}
218
219//Generic Errors
220
221func NewShellErrorOperationTimeout(msg string) Error {
222	return &err{level: EXCEPTION, ICode: OPERATION_TIMEOUT, IKey: "shell.operation.timeout", InternalMsg: OPERATION_TIMEOUT_MSG + msg, InternalCaller: CallerN(1)}
223}
224
225func NewShellErrorRowsScan(msg string) Error {
226	return &err{level: EXCEPTION, ICode: ROWS_SCAN, IKey: "shell.rows.scan.error", InternalMsg: ROWS_SCAN_MSG + msg, InternalCaller: CallerN(1)}
227}
228
229func NewShellErrorJsonMarshal(msg string) Error {
230	return &err{level: EXCEPTION, ICode: JSON_MARSHAL, IKey: "shell.json.marshal.error", InternalMsg: JSON_MARSHAL_MSG + msg, InternalCaller: CallerN(1)}
231}
232
233func NewShellErrorJsonUnmarshal(msg string) Error {
234	return &err{level: EXCEPTION, ICode: JSON_UNMARSHAL, IKey: "shell.json.unmarshal.error", InternalMsg: JSON_UNMARSHAL_MSG + msg, InternalCaller: CallerN(1)}
235}
236
237func NewShellErrorDriverQueryMethod(msg string) Error {
238	return &err{level: EXCEPTION, ICode: DRIVER_QUERY, IKey: "shell.driver.query.method.error", InternalMsg: DRIVER_QUERY_MSG + msg, InternalCaller: CallerN(1)}
239}
240
241func NewShellErrorWriterOutput(msg string) Error {
242	return &err{level: EXCEPTION, ICode: WRITER_OUTPUT, IKey: "shell.write.to.writer.error", InternalMsg: WRITER_OUTPUT_MSG + msg, InternalCaller: CallerN(1)}
243}
244
245func NewShellErrorUnbalancedParen(msg string) Error {
246	return &err{level: EXCEPTION, ICode: UNBALANCED_PAREN, IKey: "shell.unbalanced.parenthesis", InternalMsg: UNBALANCED_PAREN_MSG + msg, InternalCaller: CallerN(1)}
247}
248
249func NewShellErrorRowsClose(msg string) Error {
250	return &err{level: EXCEPTION, ICode: ROWS_CLOSE, IKey: "shell.rows.close.error", InternalMsg: ROWS_CLOSE_MSG + msg, InternalCaller: CallerN(1)}
251}
252
253func NewShellErrorCmdLineArgs(msg string) Error {
254	return &err{level: EXCEPTION, ICode: CMD_LINE_ARG, IKey: "shell.command.line.args", InternalMsg: CMD_LINE_ARG_MSG + msg, InternalCaller: CallerN(1)}
255}
256
257func NewShellErrorInvalidInputArguments(msg string) Error {
258	return &err{level: EXCEPTION, ICode: INVALID_INPUT_ARGUMENTS, IKey: "shell.invalid.input.arguments", InternalMsg: INVALID_INPUT_ARGUMENTS_MSG + msg, InternalCaller: CallerN(1)}
259}
260
261func NewShellErrorUnkownError(msg string) Error {
262	return &err{level: EXCEPTION, ICode: UNKNOWN_ERROR, IKey: "shell.internal.error.uncaptured", InternalMsg: UNKNOWN_ERROR_MSG + msg, InternalCaller: CallerN(1)}
263}
264