UNPKG

37 kBJavaScriptView Raw
1// Copyright (c) 2022, 2024, Oracle and/or its affiliates.
2
3//-----------------------------------------------------------------------------
4//
5// This software is dual-licensed to you under the Universal Permissive License
6// (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
7// 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
8// either license.
9//
10// If you elect to accept the software under the Apache License, Version 2.0,
11// the following applies:
12//
13// Licensed under the Apache License, Version 2.0 (the "License");
14// you may not use this file except in compliance with the License.
15// You may obtain a copy of the License at
16//
17// https://www.apache.org/licenses/LICENSE-2.0
18//
19// Unless required by applicable law or agreed to in writing, software
20// distributed under the License is distributed on an "AS IS" BASIS,
21// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22// See the License for the specific language governing permissions and
23// limitations under the License.
24//
25//-----------------------------------------------------------------------------
26
27'use strict';
28
29const util = require('util');
30
31// define error prefix for all messages
32const ERR_PREFIX = "NJS";
33
34// define error number constants (used in JavaScript library)
35const ERR_INVALID_POOL = 2;
36const ERR_INVALID_CONNECTION = 3;
37const ERR_INVALID_PROPERTY_VALUE = 4;
38const ERR_INVALID_PARAMETER_VALUE = 5;
39const ERR_INVALID_PROPERTY_VALUE_IN_PARAM = 7;
40const ERR_INVALID_NUMBER_OF_PARAMETERS = 9;
41const ERR_UNSUPPORTED_DATA_TYPE = 10;
42const ERR_BIND_VALUE_AND_TYPE_MISMATCH = 11;
43const ERR_INVALID_BIND_DATA_TYPE = 12;
44const ERR_INVALID_BIND_DIRECTION = 13;
45const ERR_NO_TYPE_FOR_CONVERSION = 15;
46const ERR_INSUFFICIENT_BUFFER_FOR_BINDS = 16;
47const ERR_BUSY_RS = 17;
48const ERR_INVALID_RS = 18;
49const ERR_NOT_A_QUERY = 19;
50const ERR_INVALID_TYPE_FOR_CONVERSION = 21;
51const ERR_INVALID_LOB = 22;
52const ERR_BUSY_LOB = 23;
53const ERR_INSUFFICIENT_MEMORY = 24;
54const ERR_INVALID_TYPE_FOR_ARRAY_BIND = 34;
55const ERR_REQUIRED_MAX_ARRAY_SIZE = 35;
56const ERR_INVALID_ARRAY_SIZE = 36;
57const ERR_INCOMPATIBLE_TYPE_ARRAY_BIND = 37;
58const ERR_CONN_REQUEST_TIMEOUT = 40;
59const ERR_CANNOT_CONVERT_RS_TO_STREAM = 41;
60const ERR_CANNOT_INVOKE_RS_METHODS = 42;
61const ERR_RS_ALREADY_CONVERTED = 43;
62const ERR_INVALID_BIND_UNIT = 44;
63const ERR_CANNOT_LOAD_BINARY = 45;
64const ERR_POOL_WITH_ALIAS_ALREADY_EXISTS = 46;
65const ERR_POOL_WITH_ALIAS_NOT_FOUND = 47;
66const ERR_INCOMPATIBLE_TYPE_ARRAY_INDEX_BIND = 52;
67const ERR_MIXED_BIND = 55;
68const ERR_MISSING_MAX_SIZE_BY_POS = 56;
69const ERR_MISSING_MAX_SIZE_BY_NAME = 57;
70const ERR_MAX_SIZE_TOO_SMALL = 58;
71const ERR_MISSING_TYPE_BY_POS = 59;
72const ERR_MISSING_TYPE_BY_NAME = 60;
73const ERR_INVALID_SUBSCR = 61;
74const ERR_MISSING_SUBSCR_CALLBACK = 62;
75const ERR_MISSING_SUBSCR_SQL = 63;
76const ERR_POOL_CLOSING = 64;
77const ERR_POOL_CLOSED = 65;
78const ERR_INVALID_SODA_DOC_CURSOR = 66;
79const ERR_NO_BINARY_AVAILABLE = 67;
80const ERR_INVALID_ERR_NUM = 68;
81const ERR_NODE_TOO_OLD = 69;
82const ERR_INVALID_AQ_MESSAGE = 70;
83const ERR_DBL_CONNECT_STRING = 75;
84const ERR_QUEUE_MAX_EXCEEDED = 76;
85const ERR_UNSUPPORTED_DATA_TYPE_IN_JSON = 78;
86const ERR_DBL_USER = 80;
87const ERR_CONCURRENT_OPS = 81;
88const ERR_POOL_RECONFIGURING = 82;
89const ERR_POOL_STATISTICS_DISABLED = 83;
90const ERR_TOKEN_BASED_AUTH = 84;
91const ERR_POOL_TOKEN_BASED_AUTH = 85;
92const ERR_CONN_TOKEN_BASED_AUTH = 86;
93const ERR_TOKEN_HAS_EXPIRED = 87;
94const ERR_NOT_IMPLEMENTED = 89;
95const ERR_INIT_ORACLE_CLIENT_ARGS = 90;
96const ERR_MISSING_FILE = 91;
97const ERR_INVALID_NUMBER_OF_CONNECTIONS = 92;
98const ERR_EXEC_MODE_ONLY_FOR_DML = 95;
99const ERR_INVALID_BIND_NAME = 97;
100const ERR_WRONG_NUMBER_OF_POSITIONAL_BINDS = 98;
101const ERR_BUFFER_LENGTH_INSUFFICIENT = 99;
102const ERR_NCHAR_CS_NOT_SUPPORTED = 100;
103const ERR_MISSING_CREDENTIALS = 101;
104const ERR_UNEXPECTED_END_OF_DATA = 102;
105const ERR_UNEXPECTED_MESSAGE_TYPE = 103;
106const ERR_POOL_HAS_BUSY_CONNECTIONS = 104;
107const ERR_NAN_VALUE = 105;
108const ERR_INTERNAL = 106;
109const ERR_INVALID_REF_CURSOR = 107;
110const ERR_INVALID_TYPE_NUM = 109;
111const ERR_INVALID_ORACLE_TYPE_NUM = 110;
112const ERR_UNEXPECTED_NEGATIVE_INTEGER = 111;
113const ERR_INTEGER_TOO_LARGE = 112;
114const ERR_UNEXPECTED_DATA = 113;
115const ERR_OSON_FIELD_NAME_LIMITATION = 114;
116const ERR_ORACLE_NUMBER_NO_REPR = 115;
117const ERR_UNSUPPORTED_VERIFIER_TYPE = 116;
118const ERR_THIN_CONNECTION_ALREADY_CREATED = 118;
119const ERR_UNSUPPORTED_CONVERSION = 119;
120const ERR_FETCH_TYPE_HANDLER_RETURN_VALUE = 120;
121const ERR_FETCH_TYPE_HANDLER_TYPE = 121;
122const ERR_FETCH_TYPE_HANDLER_CONVERTER = 122;
123const ERR_CALL_TIMEOUT_EXCEEDED = 123;
124const ERR_EMPTY_CONNECT_STRING = 125;
125const ERR_OSON_VERSION_NOT_SUPPORTED = 126;
126const ERR_UNKOWN_SERVER_SIDE_PIGGYBACK = 127;
127const ERR_UNKNOWN_COLUMN_TYPE_NAME = 128;
128const ERR_INVALID_OBJECT_TYPE_NAME = 129;
129const ERR_TDS_TYPE_NOT_SUPPORTED = 130;
130const ERR_INVALID_COLL_INDEX_SET = 131;
131const ERR_INVALID_COLL_INDEX_GET = 132;
132const ERR_DELETE_ELEMENTS_OF_VARRAY = 133;
133const ERR_WRONG_VALUE_FOR_DBOBJECT_ATTR = 134;
134const ERR_WRONG_VALUE_FOR_DBOBJECT_ELEM = 135;
135const ERR_WRONG_CRED_FOR_EXTAUTH = 136;
136const ERR_MISSING_BIND_VALUE = 137;
137const ERR_SERVER_VERSION_NOT_SUPPORTED = 138;
138const ERR_UNEXPECTED_XML_TYPE = 139;
139const ERR_WRONG_USER_FORMAT_EXTAUTH_PROXY = 140;
140const ERR_TOO_MANY_BATCH_ERRORS = 141;
141const ERR_WRONG_LENGTH_FOR_DBOBJECT_ATTR = 142;
142const ERR_WRONG_LENGTH_FOR_DBOBJECT_ELEM = 143;
143const ERR_VECTOR_FORMAT_NOT_SUPPORTED = 144;
144const ERR_VECTOR_VERSION_NOT_SUPPORTED = 145;
145const ERR_OBJECT_IS_NOT_A_COLLECTION = 146;
146
147// Oracle Net layer errors start from 500
148const ERR_CONNECTION_CLOSED = 500;
149const ERR_CONNECTION_LOSTCONTACT = 501;
150const ERR_CONNECTION_INCOMPLETE = 503;
151const ERR_PROXY_CONNECTION_FAILURE = 504;
152const ERR_TLS_INIT_FAILURE = 505;
153const ERR_TLS_AUTH_FAILURE = 506;
154const ERR_TLS_DNMATCH_FAILURE = 507;
155const ERR_TLS_HOSTMATCH_FAILURE = 508;
156const ERR_INVALID_PACKET = 509;
157const ERR_CONNECTION_TIMEDOUT = 510;
158const ERR_CONNECTION_REFUSED = 511;
159const ERR_INVALID_CONNECT_STRING_PARAMETERS = 512;
160const ERR_CONNECTION_INBAND = 513;
161const ERR_INVALID_CONNECT_STRING_SYNTAX = 514;
162const ERR_INVALID_EZCONNECT_SYNTAX = 515;
163const ERR_NO_CONFIG_DIR = 516;
164const ERR_TNS_ENTRY_NOT_FOUND = 517;
165const ERR_INVALID_SERVICE_NAME = 518;
166const ERR_INVALID_SID = 519;
167const ERR_TNS_NAMES_FILE_MISSING = 520;
168const ERR_CONNECTION_EOF = 521;
169
170// Oracle SUCCESS_WITH_INFO warning start from 700
171const WRN_COMPILATION_CREATE = 700;
172
173// define mapping for ODPI-C, OCI & ORA errors that need to be wrapped
174// with NJS errors
175const adjustErrorXref = new Map();
176adjustErrorXref.set("DPI-1010", ERR_INVALID_CONNECTION);
177adjustErrorXref.set("DPI-1024", [ERR_INVALID_COLL_INDEX_GET, 'at index ([0-9]+) does']);
178adjustErrorXref.set("DPI-1044", ERR_ORACLE_NUMBER_NO_REPR);
179adjustErrorXref.set("DPI-1055", ERR_NAN_VALUE);
180adjustErrorXref.set("DPI-1063", ERR_EXEC_MODE_ONLY_FOR_DML);
181adjustErrorXref.set("DPI-1067", [ERR_CALL_TIMEOUT_EXCEEDED, "call timeout of ([0-9]+) ms"]);
182adjustErrorXref.set("DPI-1080", ERR_CONNECTION_CLOSED);
183adjustErrorXref.set("OCI-22303", [ERR_INVALID_OBJECT_TYPE_NAME, 'type "([^"]*"."[^"]*)"']);
184adjustErrorXref.set("OCI-22164", ERR_DELETE_ELEMENTS_OF_VARRAY);
185adjustErrorXref.set("OCI-22165", [ERR_INVALID_COLL_INDEX_SET, /index \[([0-9]+)\] must be in the range of \[([0-9]+)\] to \[([0-9]+)\]/]);
186adjustErrorXref.set("ORA-00028", ERR_CONNECTION_CLOSED);
187adjustErrorXref.set("ORA-00600", ERR_CONNECTION_CLOSED);
188adjustErrorXref.set("ORA-24338", ERR_INVALID_REF_CURSOR);
189adjustErrorXref.set("ORA-25708", ERR_TOKEN_HAS_EXPIRED);
190adjustErrorXref.set("ORA-24344", WRN_COMPILATION_CREATE);
191
192// define mapping for error messages
193const messages = new Map();
194messages.set(ERR_INVALID_POOL, // NJS-002
195 'invalid pool');
196messages.set(ERR_INVALID_CONNECTION, // NJS-003
197 'invalid or closed connection');
198messages.set(ERR_INVALID_PROPERTY_VALUE, // NJS-004
199 'invalid value for property "%s"');
200messages.set(ERR_INVALID_PARAMETER_VALUE, // NJS-005
201 'invalid value for parameter %d');
202messages.set(ERR_INVALID_PROPERTY_VALUE_IN_PARAM, // NJS-007
203 'invalid value for "%s" in parameter %d');
204messages.set(ERR_INVALID_NUMBER_OF_PARAMETERS, // NJS-009
205 'invalid number of parameters');
206// used in C -- keep synchronized!
207messages.set(ERR_UNSUPPORTED_DATA_TYPE, // NJS-010
208 'unsupported data type %d in column %d');
209messages.set(ERR_BIND_VALUE_AND_TYPE_MISMATCH, // NJS-011
210 'encountered bind value and type mismatch');
211messages.set(ERR_INVALID_BIND_DATA_TYPE, // NJS-012
212 'encountered invalid bind data type in parameter %d');
213messages.set(ERR_INVALID_BIND_DIRECTION, // NJS-013
214 'invalid bind direction');
215messages.set(ERR_NO_TYPE_FOR_CONVERSION, // NJS-015
216 'type was not specified for conversion');
217// used in C -- keep synchronized!
218messages.set(ERR_INSUFFICIENT_BUFFER_FOR_BINDS, // NJS-016
219 'buffer is too small for OUT binds');
220messages.set(ERR_BUSY_RS, // NJS-017
221 'concurrent operations on ResultSet are not allowed');
222messages.set(ERR_INVALID_RS, // NJS-018
223 'invalid ResultSet');
224messages.set(ERR_NOT_A_QUERY, // NJS-019
225 'ResultSet cannot be returned for non-query statements');
226messages.set(ERR_INVALID_TYPE_FOR_CONVERSION, // NJS-021
227 'invalid type for conversion specified');
228messages.set(ERR_INVALID_LOB, // NJS-022
229 'invalid Lob');
230messages.set(ERR_BUSY_LOB, // NJS-023
231 'concurrent operations on a Lob are not allowed');
232// used in C -- keep synchronized!
233messages.set(ERR_INSUFFICIENT_MEMORY, // NJS-024
234 'memory allocation failed');
235messages.set(ERR_INVALID_TYPE_FOR_ARRAY_BIND, // NJS-034
236 'data type is unsupported for array bind');
237messages.set(ERR_REQUIRED_MAX_ARRAY_SIZE, // NJS-035
238 'maxArraySize is required for IN OUT array bind');
239messages.set(ERR_INVALID_ARRAY_SIZE, // NJS-036
240 'length of given array is greater than "maxArraySize"');
241messages.set(ERR_INCOMPATIBLE_TYPE_ARRAY_BIND, // NJS-037
242 'invalid data type at array index %d for bind ":%s"');
243messages.set(ERR_CONN_REQUEST_TIMEOUT, // NJS-040
244 'connection request timeout. Request exceeded "queueTimeout" of %d');
245messages.set(ERR_CANNOT_CONVERT_RS_TO_STREAM, // NJS-041
246 'cannot convert ResultSet to QueryStream after invoking methods');
247messages.set(ERR_CANNOT_INVOKE_RS_METHODS, // NJS-042
248 'cannot invoke ResultSet methods after converting to QueryStream');
249messages.set(ERR_RS_ALREADY_CONVERTED, // NJS-043
250 'ResultSet already converted to QueryStream');
251messages.set(ERR_INVALID_BIND_UNIT, // NJS-044
252 'bind object must contain one of the following attributes: "dir", "type", "maxSize", or "val"');
253messages.set(ERR_CANNOT_LOAD_BINARY, // NJS-045
254 'cannot load a node-oracledb Thick mode binary for Node.js. Please try using Thin mode. %s');
255messages.set(ERR_POOL_WITH_ALIAS_ALREADY_EXISTS, // NJS-046
256 'pool alias "%s" already exists in the connection pool cache');
257messages.set(ERR_POOL_WITH_ALIAS_NOT_FOUND, // NJS-047
258 'pool alias "%s" not found in connection pool cache');
259messages.set(ERR_INCOMPATIBLE_TYPE_ARRAY_INDEX_BIND, // NJS-052
260 'invalid data type at array index %d for bind position %d');
261messages.set(ERR_MIXED_BIND, // NJS-055
262 'binding by position and name cannot be mixed');
263messages.set(ERR_MISSING_MAX_SIZE_BY_POS, // NJS-056
264 'maxSize for bind position %d must be specified and be greater than zero');
265messages.set(ERR_MISSING_MAX_SIZE_BY_NAME, // NJS-057
266 'maxSize for bind "%s" must be specified and greater than zero');
267messages.set(ERR_MAX_SIZE_TOO_SMALL, // NJS-058
268 'maxSize of %d is too small for value of length %d in row %d');
269messages.set(ERR_MISSING_TYPE_BY_POS, // NJS-059
270 'type must be specified for bind position %d');
271messages.set(ERR_MISSING_TYPE_BY_NAME, // NJS-060
272 'type must be specified for bind "%s"');
273messages.set(ERR_INVALID_SUBSCR, // NJS-061
274 'invalid subscription');
275messages.set(ERR_MISSING_SUBSCR_CALLBACK, // NJS-062
276 'subscription notification callback missing');
277messages.set(ERR_MISSING_SUBSCR_SQL, // NJS-063
278 'subscription notification SQL missing');
279messages.set(ERR_POOL_CLOSING, // NJS-064
280 'connection pool is closing');
281messages.set(ERR_POOL_CLOSED, // NJS-065
282 'connection pool was closed');
283messages.set(ERR_INVALID_SODA_DOC_CURSOR, // NJS-066
284 'invalid SODA document cursor');
285messages.set(ERR_NO_BINARY_AVAILABLE, // NJS-067
286 'a pre-built node-oracledb Thick mode binary was not found for %s');
287messages.set(ERR_INVALID_ERR_NUM, // NJS-068
288 'invalid error number %d supplied');
289messages.set(ERR_NODE_TOO_OLD, // NJS-069
290 'node-oracledb %s requires Node.js %s or later');
291messages.set(ERR_INVALID_AQ_MESSAGE, // NJS-070
292 'message must be a string, buffer, database object or an object containing a payload property which itself is a string, buffer or database object');
293messages.set(ERR_DBL_CONNECT_STRING, // NJS-075
294 'only one of "connectString" and "connectionString" can be used');
295messages.set(ERR_QUEUE_MAX_EXCEEDED, // NJS-076
296 'connection request rejected. Pool queue length "queueMax" %d reached');
297// used in C -- keep synchronized!
298messages.set(ERR_UNSUPPORTED_DATA_TYPE_IN_JSON, // NJS-078
299 'unsupported data type %d in JSON value');
300messages.set(ERR_DBL_USER, // NJS-080
301 'only one of "user" and "username" can be used');
302messages.set(ERR_CONCURRENT_OPS, // NJS-081
303 'concurrent operations on a connection are disabled');
304messages.set(ERR_POOL_RECONFIGURING, // NJS-082
305 'connection pool is being reconfigured');
306messages.set(ERR_POOL_STATISTICS_DISABLED, // NJS-083
307 'pool statistics are not enabled');
308messages.set(ERR_TOKEN_BASED_AUTH, // NJS-084
309 'invalid access token');
310messages.set(ERR_POOL_TOKEN_BASED_AUTH, // NJS-085
311 'invalid connection pool configuration with token-based authentication. The "homogeneous" and "externalAuth" attributes must be set to true');
312messages.set(ERR_CONN_TOKEN_BASED_AUTH, // NJS-086
313 'invalid standalone configuration with token-based authentication. The "externalAuth" attribute must be set to true');
314messages.set(ERR_TOKEN_HAS_EXPIRED, // NJS-087
315 'access token has expired');
316messages.set(ERR_NOT_IMPLEMENTED, // NJS-089
317 '%s is not supported by node-oracledb in Thin mode');
318messages.set(ERR_INIT_ORACLE_CLIENT_ARGS, // NJS-090
319 'initOracleClient() was already called with different arguments');
320messages.set(ERR_MISSING_FILE, // NJS-091
321 'file %s is missing');
322messages.set(ERR_INVALID_NUMBER_OF_CONNECTIONS, // NJS-092
323 '"poolMax" %d must be greater than or equal to "poolMin" %d');
324messages.set(ERR_EXEC_MODE_ONLY_FOR_DML, // NJS-095
325 'setting "batchErrors" or "dmlRowCounts" to true is only permitted for DML statements');
326messages.set(ERR_INVALID_BIND_NAME, // NJS-097
327 'no bind placeholder named ":%s" was found in the statement text');
328messages.set(ERR_WRONG_NUMBER_OF_POSITIONAL_BINDS, // NJS-098
329 '%s positional bind values are required but %s were provided');
330messages.set(ERR_BUFFER_LENGTH_INSUFFICIENT, // NJS-099
331 'internal error: buffer of length %s insufficient to hold %s bytes');
332messages.set(ERR_NCHAR_CS_NOT_SUPPORTED, // NJS-100
333 'national character set id %d is not supported by node-oracledb in Thin mode');
334messages.set(ERR_MISSING_CREDENTIALS, // NJS-101
335 'no credentials specified');
336messages.set(ERR_UNEXPECTED_END_OF_DATA, // NJS-102
337 'unexpected end of data: want %d bytes but only %d bytes are available');
338messages.set(ERR_UNEXPECTED_MESSAGE_TYPE, // NJS-103
339 'unexpected message type %d received at position %d of packet %d');
340messages.set(ERR_POOL_HAS_BUSY_CONNECTIONS, // NJS-104
341 'connection pool cannot be closed because connections are busy');
342messages.set(ERR_NAN_VALUE, // NJS-105
343 'value is not a number (NaN) and cannot be used in Oracle Database numbers');
344messages.set(ERR_INTERNAL, // NJS-106
345 'internal error: %s');
346messages.set(ERR_INVALID_REF_CURSOR, // NJS-107
347 'invalid cursor');
348messages.set(ERR_INVALID_TYPE_NUM, // NJS-109
349 'invalid type number %d');
350messages.set(ERR_INVALID_ORACLE_TYPE_NUM, // NJS-110
351 'invalid Oracle type number %d [csfrm: %d]');
352messages.set(ERR_UNEXPECTED_NEGATIVE_INTEGER, // NJS-111
353 'internal error: read a negative integer when expecting a positive integer at position %d of packet %d');
354messages.set(ERR_INTEGER_TOO_LARGE, // NJS-112
355 'internal error: read integer of length %d when expecting integer of no more than length %d at position %d of packet %d');
356messages.set(ERR_UNEXPECTED_DATA, // NJS-113
357 'unexpected data received: %s');
358messages.set(ERR_OSON_FIELD_NAME_LIMITATION, // NJS-114
359 'OSON field names may not exceed 255 UTF-8 encoded bytes');
360messages.set(ERR_ORACLE_NUMBER_NO_REPR, // NJS-115
361 'value cannot be represented as an Oracle Database number');
362messages.set(ERR_UNSUPPORTED_VERIFIER_TYPE, // NJS-116
363 'password verifier type 0x%s is not supported by node-oracledb in Thin mode');
364messages.set(ERR_THIN_CONNECTION_ALREADY_CREATED, // NJS-118
365 'node-oracledb Thick mode cannot be enabled because a Thin mode connection has already been created');
366messages.set(ERR_UNSUPPORTED_CONVERSION, // NJS-119
367 'conversion from type %s to type %s is not supported');
368messages.set(ERR_FETCH_TYPE_HANDLER_RETURN_VALUE, // NJS-120
369 'fetchTypeHandler return value must be an object');
370messages.set(ERR_FETCH_TYPE_HANDLER_TYPE, // NJS-121
371 'fetchTypeHandler return value attribute "type" must be a valid database type');
372messages.set(ERR_FETCH_TYPE_HANDLER_CONVERTER, // NJS-122
373 'fetchTypeHandler return value attribute "converter" must be a function');
374messages.set(ERR_CALL_TIMEOUT_EXCEEDED, // NJS-123
375 'call timeout of %d ms exceeded');
376messages.set(ERR_EMPTY_CONNECT_STRING, // NJS-125
377 '"connectString" cannot be empty or undefined. Bequeath connections are not supported in Thin mode');
378messages.set(ERR_OSON_VERSION_NOT_SUPPORTED, // NJS-126
379 'OSON version %s is not supported');
380messages.set(ERR_UNKOWN_SERVER_SIDE_PIGGYBACK, // NJS-127
381 'internal error: unknown server side piggyback opcode %s');
382messages.set(ERR_UNKNOWN_COLUMN_TYPE_NAME, // NJS-128
383 'internal error: unknown column type name "%s"');
384messages.set(ERR_INVALID_OBJECT_TYPE_NAME, // NJS-129
385 'invalid object type name: "%s"');
386messages.set(ERR_TDS_TYPE_NOT_SUPPORTED, // NJS-130
387 'Oracle TDS data type %d is not supported');
388messages.set(ERR_INVALID_COLL_INDEX_SET, // NJS-131
389 'given index %d must be in the range of %d to %d');
390messages.set(ERR_INVALID_COLL_INDEX_GET, // NJS-132
391 'element at index %d does not exist');
392messages.set(ERR_DELETE_ELEMENTS_OF_VARRAY, // NJS-133
393 'cannot delete elements of a VARRAY');
394messages.set(ERR_WRONG_VALUE_FOR_DBOBJECT_ATTR, // NJS-134
395 'value is of wrong type for attribute %s of object %s');
396messages.set(ERR_WRONG_VALUE_FOR_DBOBJECT_ELEM, // NJS-135
397 'value is of wrong type for an element of object %s');
398messages.set(ERR_WRONG_CRED_FOR_EXTAUTH, // NJS-136
399 'user name and password cannot be set when using external authentication');
400messages.set(ERR_MISSING_BIND_VALUE, // NJS-137
401 'a bind variable replacement value for placeholder ":%s" was not provided');
402messages.set(ERR_SERVER_VERSION_NOT_SUPPORTED, // NJS-138
403 'connections to this database server version are not supported by node-oracledb in Thin mode');
404messages.set(ERR_UNEXPECTED_XML_TYPE, // NJS-139
405 'unexpected XML type with flag %d');
406messages.set(ERR_WRONG_USER_FORMAT_EXTAUTH_PROXY, // NJS-140
407 'user name must be enclosed in [] when using external authentication with a proxy user');
408messages.set(ERR_TOO_MANY_BATCH_ERRORS, // NJS-141
409 'the number of batch errors from executemany() exceeds 65535');
410messages.set(ERR_WRONG_LENGTH_FOR_DBOBJECT_ATTR, // NJS-142
411 'value too large for attribute %s of object %s (actual: %d, maximum: %d)');
412messages.set(ERR_WRONG_LENGTH_FOR_DBOBJECT_ELEM, // NJS-143
413 'value too large for element %d of object %s (actual: %d, maximum: %d)');
414messages.set(ERR_VECTOR_FORMAT_NOT_SUPPORTED, // NJS-144
415 'VECTOR format %d is not supported');
416messages.set(ERR_VECTOR_VERSION_NOT_SUPPORTED, // NJS-145
417 'VECTOR version %d is not supported');
418messages.set(ERR_OBJECT_IS_NOT_A_COLLECTION, // NJS-146
419 'object %s is not a collection');
420
421// Oracle Net layer errors
422
423messages.set(ERR_CONNECTION_CLOSED, // NJS-500
424 'connection to the Oracle Database was broken');
425messages.set(ERR_CONNECTION_LOSTCONTACT, // NJS-501
426 'connection to host %s port %d terminated unexpectedly. (CONNECTION_ID=%s)\n%s');
427messages.set(ERR_CONNECTION_INCOMPLETE, // NJS-503
428 'connection to host %s port %d could not be established. (CONNECTION_ID=%s)\n%s');
429messages.set(ERR_PROXY_CONNECTION_FAILURE, // NJS-504
430 'connection establishment through a web proxy at host %s port %d failed. (CONNECTION_ID=%s)\n%s');
431messages.set(ERR_TLS_INIT_FAILURE, // NJS-505
432 'unable to initiate TLS connection. Please check if wallet credentials are valid');
433messages.set(ERR_TLS_AUTH_FAILURE, // NJS-506
434 'connection to host %s port %d encountered TLS handshake failure. (CONNECTION_ID=%s)\n%s');
435messages.set(ERR_TLS_DNMATCH_FAILURE, // NJS-507
436 'TLS detected an invalid certificate. Server DN in certificate does not match the specified DN');
437messages.set(ERR_TLS_HOSTMATCH_FAILURE, // NJS-508
438 'TLS detected an invalid certificate. %s not present in certificate');
439messages.set(ERR_INVALID_PACKET, // NJS-509
440 'internal error: invalid packet type or malformed packet received');
441messages.set(ERR_CONNECTION_TIMEDOUT, // NJS-510
442 'connection to host %s port %d timed out. Request exceeded "%s" of %d seconds. (CONNECTION_ID=%s)');
443messages.set(ERR_CONNECTION_REFUSED, // NJS-511
444 'connection to listener at host %s port %d was refused. (CONNECTION_ID=%s)\nCause: %s');
445messages.set(ERR_INVALID_CONNECT_STRING_PARAMETERS, // NJS-512
446 'invalid connection string parameters.\n%s');
447messages.set(ERR_CONNECTION_INBAND, // NJS-513
448 'error received through in-band notification: %s');
449messages.set(ERR_INVALID_CONNECT_STRING_SYNTAX, // NJS-514
450 'syntax error in connection string');
451messages.set(ERR_INVALID_EZCONNECT_SYNTAX, // NJS-515
452 'error in Easy Connect connection string: %s: %s');
453messages.set(ERR_NO_CONFIG_DIR, // NJS-516
454 'no configuration directory set or available to search for tnsnames.ora');
455messages.set(ERR_TNS_ENTRY_NOT_FOUND, // NJS-517
456 'cannot connect to Oracle Database. Unable to find "%s" in "%s"');
457messages.set(ERR_INVALID_SERVICE_NAME, // NJS-518
458 'cannot connect to Oracle Database. Service "%s" is not registered with the listener at host %s port %s. (CONNECTION_ID=%s)');
459messages.set(ERR_INVALID_SID, // NJS-519
460 'cannot connect to Oracle Database. SID "%s" is not registered with the listener at host %s port %s. (CONNECTION_ID=%s)');
461messages.set(ERR_TNS_NAMES_FILE_MISSING, // NJS-520
462 'cannot connect to Oracle Database. File tnsnames.ora not found in %s');
463messages.set(ERR_CONNECTION_EOF, // NJS-521
464 'connection to host %s port %d received end-of-file on communication channel. (CONNECTION_ID=%s)');
465
466// Oracle SUCCESS_WITH_INFO warning
467
468messages.set(WRN_COMPILATION_CREATE, // NJS-700
469 'creation succeeded with compilation errors');
470
471//-----------------------------------------------------------------------------
472// assert()
473//
474// Checks the condition, and if the condition is not true, throws an exception
475// using the specified error number and arguments.
476//-----------------------------------------------------------------------------
477function assert(condition) {
478 if (!condition) {
479 const args = Array.prototype.slice.call(arguments, 1);
480 throwErr(...args);
481 }
482}
483
484//-----------------------------------------------------------------------------
485// assertArgCount()
486//
487// Asserts that the argument count falls between the minimum and maximum number
488// of arguments.
489//-----------------------------------------------------------------------------
490function assertArgCount(args, minArgCount, maxArgCount) {
491 assert(args.length >= minArgCount && args.length <= maxArgCount,
492 ERR_INVALID_NUMBER_OF_PARAMETERS);
493}
494
495//-----------------------------------------------------------------------------
496// assertParamPropBool()
497//
498// Asserts that the property value of a parameter is a boolean value (or
499// undefined).
500//-----------------------------------------------------------------------------
501function assertParamPropBool(obj, parameterNum, propName) {
502 if (obj[propName] !== undefined) {
503 assertParamPropValue(typeof obj[propName] === 'boolean', parameterNum,
504 propName);
505 }
506}
507
508//-----------------------------------------------------------------------------
509// assertParamPropFunction()
510//
511// Asserts that the property value of a parameter is a function (or undefined).
512//-----------------------------------------------------------------------------
513function assertParamPropFunction(obj, parameterNum, propName) {
514 if (obj[propName] !== undefined) {
515 assertParamPropValue(typeof obj[propName] === 'function', parameterNum,
516 propName);
517 }
518}
519
520//-----------------------------------------------------------------------------
521// assertParamPropInt()
522//
523// Asserts that the property value of a parameter is an integer value (or
524// undefined).
525//-----------------------------------------------------------------------------
526function assertParamPropInt(obj, parameterNum, propName) {
527 if (obj[propName] !== undefined) {
528 assertParamPropValue(Number.isInteger(obj[propName]), parameterNum,
529 propName);
530 }
531}
532
533//-----------------------------------------------------------------------------
534// assertParamPropUnsignedInt()
535//
536// Asserts that the property value of a parameter is a positive integer value
537// (or undefined).
538//-----------------------------------------------------------------------------
539function assertParamPropUnsignedInt(obj, parameterNum, propName) {
540 if (obj[propName] !== undefined) {
541 assertParamPropValue(Number.isInteger(obj[propName]) && obj[propName] >= 0,
542 parameterNum, propName);
543 }
544}
545
546//-----------------------------------------------------------------------------
547// assertParamPropString()
548//
549// Asserts that the property value of a parameter is a string value (or undefined).
550//-----------------------------------------------------------------------------
551function assertParamPropString(obj, parameterNum, propName) {
552 if (obj[propName] !== undefined) {
553 assertParamPropValue(typeof obj[propName] === 'string', parameterNum,
554 propName);
555 }
556}
557
558//-----------------------------------------------------------------------------
559// assertParamPropValue()
560//
561// Asserts that the property value of a parameter passes the specified
562// condition.
563//-----------------------------------------------------------------------------
564function assertParamPropValue(condition, parameterNum, propName) {
565 assert(condition, ERR_INVALID_PROPERTY_VALUE_IN_PARAM, propName,
566 parameterNum);
567}
568
569//-----------------------------------------------------------------------------
570// assertParamValue()
571//
572// Asserts that the parameter value passes the specified condition.
573//-----------------------------------------------------------------------------
574function assertParamValue(condition, parameterNum) {
575 assert(condition, ERR_INVALID_PARAMETER_VALUE, parameterNum);
576}
577
578//-----------------------------------------------------------------------------
579// assertPropValue()
580//
581// Asserts that the property value passes the specified condition.
582//-----------------------------------------------------------------------------
583function assertPropValue(condition, propName) {
584 assert(condition, ERR_INVALID_PROPERTY_VALUE, propName);
585}
586
587//-----------------------------------------------------------------------------
588// getErr()
589//
590// Returns an error object with the given error number after formatting it with
591// the given arguments.
592//-----------------------------------------------------------------------------
593function getErr(errorNum) {
594 let baseText = messages.get(errorNum);
595 let args = [...arguments];
596 if (!baseText) {
597 args = [undefined, errorNum];
598 errorNum = ERR_INVALID_ERR_NUM;
599 baseText = messages.get(errorNum);
600 }
601 const errorNumStr = errorNum.toString().padStart(3, '0');
602 const code = `${ERR_PREFIX}-${errorNumStr}`;
603 args[0] = `${code}: ${baseText}`;
604 const err = new Error(util.format(...args));
605 err.code = code;
606 Error.captureStackTrace(err, getErr);
607 return err;
608}
609
610//-----------------------------------------------------------------------------
611// throwErr()
612//
613// Throws an error with the given error number after formatting it with the
614// given arguments.
615//-----------------------------------------------------------------------------
616function throwErr() {
617 throw (getErr(...arguments));
618}
619
620//-----------------------------------------------------------------------------
621// throwNotImplemented()
622//
623// Throws an error that the feature is not supported in Thin mode
624//-----------------------------------------------------------------------------
625function throwNotImplemented(feature) {
626 throwErr(ERR_NOT_IMPLEMENTED, feature);
627}
628
629//-----------------------------------------------------------------------------
630// transformErr()
631//
632// Adjusts the supplied error, if necessary, by looking for specific ODPI-C and
633// Oracle errors and replacing them with driver specific errors.
634//-----------------------------------------------------------------------------
635function transformErr(err, fnOpt) {
636 if (!err.code) {
637 const pos = err.message.indexOf(":");
638 if (pos > 0) {
639 err.code = err.message.substr(0, pos);
640 /* add Oracle Database Error Help Portal URL for database error
641 messages, but only in thin mode since this is done
642 automatically in thick mode with Oracle Client 23c and higher
643 */
644 const settings = require('./settings.js');
645 if (err.errorNum && settings.thin) {
646 err.message += '\n' + 'Help: https://docs.oracle.com/error-help/db/ora-' +
647 `${err.errorNum.toString().padStart(5, '0')}/`;
648 }
649 if (adjustErrorXref.has(err.code)) {
650 let args = [];
651 let driverErrorNum;
652 const driverErrorInfo = adjustErrorXref.get(err.code);
653 if (typeof driverErrorInfo === 'number') {
654 driverErrorNum = driverErrorInfo;
655 } else {
656 driverErrorNum = driverErrorInfo[0];
657 const pattern = driverErrorInfo[1];
658 const results = err.message.match(pattern);
659 if (results) {
660 args = results.slice(1);
661 }
662 }
663 const newErr = getErr(driverErrorNum, ...args);
664 err.code = newErr.code;
665 err.message = newErr.message + "\n" + err.message;
666 }
667 }
668 }
669
670 if (err.requiresStackCapture) {
671 delete err.requiresStackCapture;
672 Error.captureStackTrace(err, fnOpt);
673 }
674 return err;
675}
676
677// define exports
678module.exports = {
679 ERR_INVALID_POOL,
680 ERR_INVALID_CONNECTION,
681 ERR_INVALID_PROPERTY_VALUE,
682 ERR_INVALID_PARAMETER_VALUE,
683 ERR_INVALID_PROPERTY_VALUE_IN_PARAM,
684 ERR_INVALID_NUMBER_OF_PARAMETERS,
685 ERR_UNSUPPORTED_DATA_TYPE,
686 ERR_BIND_VALUE_AND_TYPE_MISMATCH,
687 ERR_INVALID_BIND_DATA_TYPE,
688 ERR_INVALID_BIND_DIRECTION,
689 ERR_NO_TYPE_FOR_CONVERSION,
690 ERR_INSUFFICIENT_BUFFER_FOR_BINDS,
691 ERR_BUSY_RS,
692 ERR_INVALID_RS,
693 ERR_NOT_A_QUERY,
694 ERR_INVALID_TYPE_FOR_CONVERSION,
695 ERR_INVALID_LOB,
696 ERR_BUSY_LOB,
697 ERR_INSUFFICIENT_MEMORY,
698 ERR_INVALID_TYPE_FOR_ARRAY_BIND,
699 ERR_REQUIRED_MAX_ARRAY_SIZE,
700 ERR_INVALID_ARRAY_SIZE,
701 ERR_INCOMPATIBLE_TYPE_ARRAY_BIND,
702 ERR_CONN_REQUEST_TIMEOUT,
703 ERR_CANNOT_CONVERT_RS_TO_STREAM,
704 ERR_CANNOT_INVOKE_RS_METHODS,
705 ERR_RS_ALREADY_CONVERTED,
706 ERR_INVALID_BIND_UNIT,
707 ERR_CANNOT_LOAD_BINARY,
708 ERR_POOL_WITH_ALIAS_ALREADY_EXISTS,
709 ERR_POOL_WITH_ALIAS_NOT_FOUND,
710 ERR_INCOMPATIBLE_TYPE_ARRAY_INDEX_BIND,
711 ERR_MIXED_BIND,
712 ERR_MISSING_MAX_SIZE_BY_POS,
713 ERR_MISSING_MAX_SIZE_BY_NAME,
714 ERR_MAX_SIZE_TOO_SMALL,
715 ERR_MISSING_TYPE_BY_POS,
716 ERR_MISSING_TYPE_BY_NAME,
717 ERR_INVALID_SUBSCR,
718 ERR_MISSING_SUBSCR_CALLBACK,
719 ERR_MISSING_SUBSCR_SQL,
720 ERR_POOL_CLOSING,
721 ERR_POOL_CLOSED,
722 ERR_INVALID_SODA_DOC_CURSOR,
723 ERR_NO_BINARY_AVAILABLE,
724 ERR_INVALID_ERR_NUM,
725 ERR_NODE_TOO_OLD,
726 ERR_INVALID_AQ_MESSAGE,
727 ERR_DBL_CONNECT_STRING,
728 ERR_QUEUE_MAX_EXCEEDED,
729 ERR_UNSUPPORTED_DATA_TYPE_IN_JSON,
730 ERR_DBL_USER,
731 ERR_CONCURRENT_OPS,
732 ERR_POOL_RECONFIGURING,
733 ERR_POOL_STATISTICS_DISABLED,
734 ERR_TOKEN_BASED_AUTH,
735 ERR_POOL_TOKEN_BASED_AUTH,
736 ERR_CONN_TOKEN_BASED_AUTH,
737 ERR_TOKEN_HAS_EXPIRED,
738 ERR_NOT_IMPLEMENTED,
739 ERR_INIT_ORACLE_CLIENT_ARGS,
740 ERR_MISSING_FILE,
741 ERR_INVALID_NUMBER_OF_CONNECTIONS,
742 ERR_EXEC_MODE_ONLY_FOR_DML,
743 ERR_CONNECTION_CLOSED,
744 ERR_CONNECTION_LOSTCONTACT,
745 ERR_CONNECTION_INCOMPLETE,
746 ERR_PROXY_CONNECTION_FAILURE,
747 ERR_TLS_INIT_FAILURE,
748 ERR_TLS_AUTH_FAILURE,
749 ERR_TLS_DNMATCH_FAILURE,
750 ERR_TLS_HOSTMATCH_FAILURE,
751 ERR_INVALID_PACKET,
752 ERR_CONNECTION_TIMEDOUT,
753 ERR_CONNECTION_REFUSED,
754 ERR_INVALID_CONNECT_STRING_PARAMETERS,
755 ERR_CONNECTION_INBAND,
756 ERR_INVALID_CONNECT_STRING_SYNTAX,
757 ERR_INVALID_EZCONNECT_SYNTAX,
758 ERR_NO_CONFIG_DIR,
759 ERR_TNS_ENTRY_NOT_FOUND,
760 ERR_CONNECTION_EOF,
761 ERR_INVALID_BIND_NAME,
762 ERR_WRONG_NUMBER_OF_POSITIONAL_BINDS,
763 ERR_BUFFER_LENGTH_INSUFFICIENT,
764 ERR_NCHAR_CS_NOT_SUPPORTED,
765 ERR_MISSING_CREDENTIALS,
766 ERR_UNEXPECTED_END_OF_DATA,
767 ERR_UNEXPECTED_MESSAGE_TYPE,
768 ERR_POOL_HAS_BUSY_CONNECTIONS,
769 ERR_INTERNAL,
770 ERR_INVALID_REF_CURSOR,
771 ERR_UNSUPPORTED_VERIFIER_TYPE,
772 ERR_NAN_VALUE,
773 ERR_ORACLE_NUMBER_NO_REPR,
774 ERR_INVALID_SERVICE_NAME,
775 ERR_INVALID_SID,
776 ERR_TNS_NAMES_FILE_MISSING,
777 ERR_INVALID_TYPE_NUM,
778 ERR_INVALID_ORACLE_TYPE_NUM,
779 ERR_UNEXPECTED_NEGATIVE_INTEGER,
780 ERR_INTEGER_TOO_LARGE,
781 ERR_UNEXPECTED_DATA,
782 ERR_OSON_FIELD_NAME_LIMITATION,
783 ERR_OSON_VERSION_NOT_SUPPORTED,
784 ERR_THIN_CONNECTION_ALREADY_CREATED,
785 ERR_UNSUPPORTED_CONVERSION,
786 ERR_FETCH_TYPE_HANDLER_RETURN_VALUE,
787 ERR_FETCH_TYPE_HANDLER_TYPE,
788 ERR_FETCH_TYPE_HANDLER_CONVERTER,
789 ERR_CALL_TIMEOUT_EXCEEDED,
790 ERR_EMPTY_CONNECT_STRING,
791 ERR_UNKOWN_SERVER_SIDE_PIGGYBACK,
792 ERR_UNKNOWN_COLUMN_TYPE_NAME,
793 ERR_INVALID_OBJECT_TYPE_NAME,
794 ERR_TDS_TYPE_NOT_SUPPORTED,
795 ERR_INVALID_COLL_INDEX_SET,
796 ERR_INVALID_COLL_INDEX_GET,
797 ERR_DELETE_ELEMENTS_OF_VARRAY,
798 ERR_WRONG_VALUE_FOR_DBOBJECT_ATTR,
799 ERR_WRONG_VALUE_FOR_DBOBJECT_ELEM,
800 ERR_WRONG_CRED_FOR_EXTAUTH,
801 ERR_MISSING_BIND_VALUE,
802 ERR_SERVER_VERSION_NOT_SUPPORTED,
803 ERR_UNEXPECTED_XML_TYPE,
804 ERR_WRONG_USER_FORMAT_EXTAUTH_PROXY,
805 ERR_TOO_MANY_BATCH_ERRORS,
806 ERR_WRONG_LENGTH_FOR_DBOBJECT_ATTR,
807 ERR_WRONG_LENGTH_FOR_DBOBJECT_ELEM,
808 ERR_VECTOR_FORMAT_NOT_SUPPORTED,
809 ERR_VECTOR_VERSION_NOT_SUPPORTED,
810 ERR_OBJECT_IS_NOT_A_COLLECTION,
811 ERR_CONNECTION_CLOSED_CODE: `${ERR_PREFIX}-${ERR_CONNECTION_CLOSED}`,
812 WRN_COMPILATION_CREATE,
813 assert,
814 assertArgCount,
815 assertParamPropBool,
816 assertParamPropFunction,
817 assertParamPropInt,
818 assertParamPropString,
819 assertParamPropUnsignedInt,
820 assertParamPropValue,
821 assertParamValue,
822 assertPropValue,
823 getErr,
824 throwErr,
825 throwNotImplemented,
826 transformErr
827};