Skip to content

Commit

Permalink
Throw NJS-003 error instead of NJS-108 when attempting a LOB operatio…
Browse files Browse the repository at this point in the history
…n on a closed connection
  • Loading branch information
sharadraju committed Mar 11, 2024
1 parent 6491597 commit 8206eb6
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 16 deletions.
5 changes: 5 additions & 0 deletions doc/src/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ Common Changes
now raised when the size constraints are violated.
`Issue #1630 <https://github.com/oracle/node-oracledb/issues/1630>`__.

#) Error ``NJS-003`` is now raised when an attempt is made to perform an
operation using a closed connection. Error ``NJS-108``, which was
earlier used to flag errors when LOB operations were attempted on a closed
or invalid connection, is now removed.

Thin Mode Changes
++++++++++++++++++

Expand Down
9 changes: 2 additions & 7 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ const ERR_POOL_HAS_BUSY_CONNECTIONS = 104;
const ERR_NAN_VALUE = 105;
const ERR_INTERNAL = 106;
const ERR_INVALID_REF_CURSOR = 107;
const ERR_LOB_CLOSED = 108;
const ERR_INVALID_TYPE_NUM = 109;
const ERR_INVALID_ORACLE_TYPE_NUM = 110;
const ERR_UNEXPECTED_NEGATIVE_INTEGER = 111;
Expand Down Expand Up @@ -173,9 +172,8 @@ const WRN_COMPILATION_CREATE = 700;
// define mapping for ODPI-C, OCI & ORA errors that need to be wrapped
// with NJS errors
const adjustErrorXref = new Map();
adjustErrorXref.set("DPI-1010", ERR_CONNECTION_CLOSED);
adjustErrorXref.set("DPI-1010", ERR_INVALID_CONNECTION);
adjustErrorXref.set("DPI-1024", [ERR_INVALID_COLL_INDEX_GET, 'at index ([0-9]+) does']);
adjustErrorXref.set("DPI-1040", ERR_LOB_CLOSED);
adjustErrorXref.set("DPI-1044", ERR_ORACLE_NUMBER_NO_REPR);
adjustErrorXref.set("DPI-1055", ERR_NAN_VALUE);
adjustErrorXref.set("DPI-1063", ERR_EXEC_MODE_ONLY_FOR_DML);
Expand All @@ -195,7 +193,7 @@ const messages = new Map();
messages.set(ERR_INVALID_POOL, // NJS-002
'invalid pool');
messages.set(ERR_INVALID_CONNECTION, // NJS-003
'invalid connection');
'invalid or closed connection');
messages.set(ERR_INVALID_PROPERTY_VALUE, // NJS-004
'invalid value for property "%s"');
messages.set(ERR_INVALID_PARAMETER_VALUE, // NJS-005
Expand Down Expand Up @@ -346,8 +344,6 @@ messages.set(ERR_INTERNAL, // NJS-106
'internal error: %s');
messages.set(ERR_INVALID_REF_CURSOR, // NJS-107
'invalid cursor');
messages.set(ERR_LOB_CLOSED, // NJS-108
'LOB was already closed');
messages.set(ERR_INVALID_TYPE_NUM, // NJS-109
'invalid type number %d');
messages.set(ERR_INVALID_ORACLE_TYPE_NUM, // NJS-110
Expand Down Expand Up @@ -771,7 +767,6 @@ module.exports = {
ERR_INVALID_REF_CURSOR,
ERR_UNSUPPORTED_VERIFIER_TYPE,
ERR_NAN_VALUE,
ERR_LOB_CLOSED,
ERR_ORACLE_NUMBER_NO_REPR,
ERR_INVALID_SERVICE_NAME,
ERR_INVALID_SID,
Expand Down
2 changes: 1 addition & 1 deletion lib/lob.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Lob extends Duplex {
// not already been closed (never called directly)
async _destroy(err, cb) {
// if LOB was already closed, nothing to do!
if (err && err.message.startsWith("NJS-108:"))
if (err && err.message.startsWith("NJS-003:"))
delete this._impl;
if (this._impl) {
const lobImpl = this._impl;
Expand Down
2 changes: 1 addition & 1 deletion lib/thin/lob.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class ThinLobImpl extends LobImpl {

checkConn() {
if (!this.conn.nscon.connected)
errors.throwErr(errors.ERR_LOB_CLOSED);
errors.throwErr(errors.ERR_INVALID_CONNECTION);
}

close() {
Expand Down
5 changes: 4 additions & 1 deletion lib/thin/protocol/packet.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022, 2023, Oracle and/or its affiliates.
// Copyright (c) 2022, 2024, Oracle and/or its affiliates.

//-----------------------------------------------------------------------------
//
Expand Down Expand Up @@ -496,6 +496,9 @@ class WritePacket extends BaseBuffer {
buf = Buffer.from(buf);
this.startPacket();
}
if (!this.nsi.ntAdapter) {
errors.throwErr(errors.ERR_INVALID_CONNECTION);
}
this.nsi.ntAdapter.send(buf);
}

Expand Down
4 changes: 1 addition & 3 deletions src/njsVariable.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019, 2023, Oracle and/or its affiliates.
// Copyright (c) 2019, 2024, Oracle and/or its affiliates.

//-----------------------------------------------------------------------------
//
Expand Down Expand Up @@ -758,10 +758,8 @@ bool njsVariable_setScalarValue(njsVariable *var, uint32_t pos, napi_env env,
njsLob *lob;
bool check;
napi_value arrBuf;
napi_value dVal;
napi_typedarray_type type;
void *rawdata = NULL;
bool isTyped = false;
size_t numElem = 0;
size_t byteOffset = 0;

Expand Down
2 changes: 1 addition & 1 deletion test/dbObject18.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ describe('242. dbObject18.js', () => {
} else {
assert.throws(
() => row.TEAM[0],
/NJS-500:/
/NJS-003:/
);
}

Expand Down
2 changes: 1 addition & 1 deletion test/lobClose.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('54. lobClose.js', function() {
lob2.on('finish', resolve);
});
},
/NJS-108:/
/NJS-003:/
);
}); // 54.4

Expand Down
2 changes: 1 addition & 1 deletion test/poolDrain.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('170. poolDrain.js', () => {

await assert.rejects(
async () => await conn.execute('select (7+8) from dual'),
/NJS-500:/
/NJS-003:/
);
}); // 170.5

Expand Down

0 comments on commit 8206eb6

Please sign in to comment.