Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postgresql-client

Package Overview
Dependencies
Maintainers
1
Versions
106
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postgresql-client - npm Package Compare versions

Comparing version 2.9.1 to 2.10.0

8

CHANGELOG.md

@@ -0,1 +1,9 @@

# v2.10.0
[2023-11-09]
### Changes
* Fixed: Error stack do not show caller function. ([`08a1a8f`](https://github.com/panates/postgresql-client/commit/08a1a8f4141b0066ae084de4f2a31d9d7e1bd4b9))
* Improved error message handling for more understandable to humans. ([`d9bbcb0`](https://github.com/panates/postgresql-client/commit/d9bbcb0b1c10ab11816bc907d2b62977831d6082))
# v2.9.1

@@ -2,0 +10,0 @@ [2023-10-03]

67

cjs/connection/connection.js

@@ -72,3 +72,3 @@ "use strict";

async connect() {
await this._intlCon.connect();
await this._captureErrorStack(this._intlCon.connect());
if (this.state === constants_js_1.ConnectionState.READY)

@@ -97,6 +97,5 @@ this._closing = false;

this._closing = true;
// @ts-ignore
if (this._intlCon.refCount > 0 && typeof terminateWait === "number" && terminateWait > 0) {
const startTime = Date.now();
return new Promise((resolve, reject) => {
return this._captureErrorStack(new Promise((resolve, reject) => {
/* istanbul ignore next */

@@ -125,3 +124,3 @@ if (this.listenerCount('debug'))

}, 50);
});
}));
}

@@ -136,4 +135,5 @@ await this._close();

*/
execute(sql, options) {
return this._intlCon.execute(sql, options).catch((e) => {
async execute(sql, options) {
return this._captureErrorStack(this._intlCon.execute(sql, options))
.catch((e) => {
throw this._handleError(e, sql);

@@ -158,3 +158,3 @@ });

const params = options?.params?.map((prm) => (prm instanceof bind_param_js_1.BindParam ? prm.value : prm));
return await statement.execute({ ...options, params });
return await this._captureErrorStack(statement.execute({ ...options, params }));
}

@@ -179,3 +179,3 @@ finally {

});
return await prepared_statement_js_1.PreparedStatement.prepare(this, sql, options);
return await this._captureErrorStack(prepared_statement_js_1.PreparedStatement.prepare(this, sql, options));
}

@@ -186,3 +186,3 @@ /**

startTransaction() {
return this._intlCon.startTransaction();
return this._captureErrorStack(this._intlCon.startTransaction());
}

@@ -193,3 +193,3 @@ /**

commit() {
return this._intlCon.commit();
return this._captureErrorStack(this._intlCon.commit());
}

@@ -200,3 +200,3 @@ /**

rollback() {
return this._intlCon.rollback();
return this._captureErrorStack(this._intlCon.rollback());
}

@@ -210,3 +210,3 @@ /**

await this._intlCon.startTransaction();
return this._intlCon.savepoint(name);
return this._captureErrorStack(this._intlCon.savepoint(name));
}

@@ -218,3 +218,3 @@ /**

rollbackToSavepoint(name) {
return this._intlCon.rollbackToSavepoint(name);
return this._captureErrorStack(this._intlCon.rollbackToSavepoint(name));
}

@@ -226,3 +226,3 @@ /**

releaseSavepoint(name) {
return this._intlCon.releaseSavepoint(name);
return this._captureErrorStack(this._intlCon.releaseSavepoint(name));
}

@@ -235,3 +235,3 @@ async listen(channel, callback) {

if (!registered)
await this.query('LISTEN ' + channel);
await this._captureErrorStack(this.query('LISTEN ' + channel));
}

@@ -242,7 +242,7 @@ async unListen(channel) {

this._notificationListeners.removeAllListeners(channel);
await this.query('UNLISTEN ' + channel);
await this._captureErrorStack(this.query('UNLISTEN ' + channel));
}
async unListenAll() {
this._notificationListeners.removeAllListeners();
await this.query('UNLISTEN *');
await this._captureErrorStack(this.query('UNLISTEN *'));
}

@@ -255,7 +255,7 @@ _handleNotification(msg) {

if (this._pool) {
await this._pool.release(this);
await this._captureErrorStack(this._pool.release(this));
this.emit("release");
}
else
await this._intlCon.close();
await this._captureErrorStack(this._intlCon.close());
this._closing = false;

@@ -265,13 +265,28 @@ }

if (err.position) {
let s = script.substring(0, err.position - 1);
err.lineNr = s ? (s.match(/\n/g) || []).length : 0;
const lineStart = s.lastIndexOf("\n") + 1;
const lineEnd = script.indexOf("\n", lineStart);
s = script.substring(0, lineStart);
err.colNr = err.position - s.length;
err.line = lineEnd > 0 ? script.substring(lineStart, lineEnd) : script.substring(lineStart);
const i1 = script.lastIndexOf('\n', err.position) + 1;
let i2 = script.indexOf('\n', err.position);
if (i2 < 0)
i2 = Number.MAX_SAFE_INTEGER;
err.line = script.substring(i1, i2);
err.lineNr = [...script.substring(0, i1).matchAll(/\n/g)].length;
err.colNr = err.position - i1;
err.message +=
`\nAt line ${err.lineNr} column ${err.colNr}` +
`\n | ${err.line}\n | ${' '.repeat(Math.max(err.colNr - 2, 0))}-^-`;
}
return err;
}
async _captureErrorStack(promise) {
const stack = new Error().stack;
return promise.catch(e => {
if (e instanceof Error && stack) {
e.stack = stack
.split('\n')
.filter(x => !x.includes('Connection._captureErrorStack'))
.join('\n');
}
throw e;
});
}
}
exports.Connection = Connection;

@@ -69,3 +69,3 @@ import { ConnectionState } from '../constants.js';

async connect() {
await this._intlCon.connect();
await this._captureErrorStack(this._intlCon.connect());
if (this.state === ConnectionState.READY)

@@ -94,6 +94,5 @@ this._closing = false;

this._closing = true;
// @ts-ignore
if (this._intlCon.refCount > 0 && typeof terminateWait === "number" && terminateWait > 0) {
const startTime = Date.now();
return new Promise((resolve, reject) => {
return this._captureErrorStack(new Promise((resolve, reject) => {
/* istanbul ignore next */

@@ -122,3 +121,3 @@ if (this.listenerCount('debug'))

}, 50);
});
}));
}

@@ -133,4 +132,5 @@ await this._close();

*/
execute(sql, options) {
return this._intlCon.execute(sql, options).catch((e) => {
async execute(sql, options) {
return this._captureErrorStack(this._intlCon.execute(sql, options))
.catch((e) => {
throw this._handleError(e, sql);

@@ -155,3 +155,3 @@ });

const params = options?.params?.map((prm) => (prm instanceof BindParam ? prm.value : prm));
return await statement.execute({ ...options, params });
return await this._captureErrorStack(statement.execute({ ...options, params }));
}

@@ -176,3 +176,3 @@ finally {

});
return await PreparedStatement.prepare(this, sql, options);
return await this._captureErrorStack(PreparedStatement.prepare(this, sql, options));
}

@@ -183,3 +183,3 @@ /**

startTransaction() {
return this._intlCon.startTransaction();
return this._captureErrorStack(this._intlCon.startTransaction());
}

@@ -190,3 +190,3 @@ /**

commit() {
return this._intlCon.commit();
return this._captureErrorStack(this._intlCon.commit());
}

@@ -197,3 +197,3 @@ /**

rollback() {
return this._intlCon.rollback();
return this._captureErrorStack(this._intlCon.rollback());
}

@@ -207,3 +207,3 @@ /**

await this._intlCon.startTransaction();
return this._intlCon.savepoint(name);
return this._captureErrorStack(this._intlCon.savepoint(name));
}

@@ -215,3 +215,3 @@ /**

rollbackToSavepoint(name) {
return this._intlCon.rollbackToSavepoint(name);
return this._captureErrorStack(this._intlCon.rollbackToSavepoint(name));
}

@@ -223,3 +223,3 @@ /**

releaseSavepoint(name) {
return this._intlCon.releaseSavepoint(name);
return this._captureErrorStack(this._intlCon.releaseSavepoint(name));
}

@@ -232,3 +232,3 @@ async listen(channel, callback) {

if (!registered)
await this.query('LISTEN ' + channel);
await this._captureErrorStack(this.query('LISTEN ' + channel));
}

@@ -239,7 +239,7 @@ async unListen(channel) {

this._notificationListeners.removeAllListeners(channel);
await this.query('UNLISTEN ' + channel);
await this._captureErrorStack(this.query('UNLISTEN ' + channel));
}
async unListenAll() {
this._notificationListeners.removeAllListeners();
await this.query('UNLISTEN *');
await this._captureErrorStack(this.query('UNLISTEN *'));
}

@@ -252,7 +252,7 @@ _handleNotification(msg) {

if (this._pool) {
await this._pool.release(this);
await this._captureErrorStack(this._pool.release(this));
this.emit("release");
}
else
await this._intlCon.close();
await this._captureErrorStack(this._intlCon.close());
this._closing = false;

@@ -262,12 +262,27 @@ }

if (err.position) {
let s = script.substring(0, err.position - 1);
err.lineNr = s ? (s.match(/\n/g) || []).length : 0;
const lineStart = s.lastIndexOf("\n") + 1;
const lineEnd = script.indexOf("\n", lineStart);
s = script.substring(0, lineStart);
err.colNr = err.position - s.length;
err.line = lineEnd > 0 ? script.substring(lineStart, lineEnd) : script.substring(lineStart);
const i1 = script.lastIndexOf('\n', err.position) + 1;
let i2 = script.indexOf('\n', err.position);
if (i2 < 0)
i2 = Number.MAX_SAFE_INTEGER;
err.line = script.substring(i1, i2);
err.lineNr = [...script.substring(0, i1).matchAll(/\n/g)].length;
err.colNr = err.position - i1;
err.message +=
`\nAt line ${err.lineNr} column ${err.colNr}` +
`\n | ${err.line}\n | ${' '.repeat(Math.max(err.colNr - 2, 0))}-^-`;
}
return err;
}
async _captureErrorStack(promise) {
const stack = new Error().stack;
return promise.catch(e => {
if (e instanceof Error && stack) {
e.stack = stack
.split('\n')
.filter(x => !x.includes('Connection._captureErrorStack'))
.join('\n');
}
throw e;
});
}
}
{
"name": "postgresql-client",
"description": "Enterprise level PostgreSQL client for JavaScript",
"version": "2.9.1",
"version": "2.10.0",
"author": "Panates",

@@ -6,0 +6,0 @@ "contributors": [

@@ -107,2 +107,3 @@ import { ConnectionState } from '../constants.js';

protected _handleError(err: DatabaseError, script: string): DatabaseError;
protected _captureErrorStack<T>(promise: Promise<T>): Promise<T>;
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc