Skip to content

Commit 859b73c

Browse files
committed
final lines.
1 parent 6b096fc commit 859b73c

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

lib/database.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ function Database(cn, dc, config) {
650650
* Custom data streaming, with the help of $[pg-query-stream].
651651
*
652652
* This method doesn't work with the $[Native Bindings], and if option `pgNative`
653-
* is set, it will reject with `Streaming doesn't work with native bindings.`
653+
* is set, it will reject with `Streaming doesn't work with Native Bindings.`
654654
*
655655
* @param {QueryStream} qs
656656
* Stream object of type $[QueryStream].

lib/query.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function $query(ctx, query, values, qrm, config) {
7777

7878
if (!error) {
7979
if (!pgFormatting && !$npm.utils.isText(query)) {
80-
error = new Error(isFunc ? "Invalid function name." : "Invalid query format.");
80+
error = new TypeError(isFunc ? "Invalid function name." : "Invalid query format.");
8181
}
8282
if (query instanceof ExternalQuery) {
8383
var qp = query.parse();
@@ -94,7 +94,7 @@ function $query(ctx, query, values, qrm, config) {
9494
qrm = $npm.result.any; // default query result;
9595
} else {
9696
if (qrm !== parseInt(qrm) || (qrm & badMask) === badMask || qrm < 1 || qrm > 6) {
97-
error = new Error("Invalid Query Result Mask specified.");
97+
error = new TypeError("Invalid Query Result Mask specified.");
9898
}
9999
}
100100
}

lib/stream.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function $stream(ctx, qs, initCB, config) {
1515
// istanbul ignore next:
1616
// we do not provide code coverage for the Native Bindings specifics
1717
if (ctx.options.pgNative) {
18-
return $p.reject(new Error("Streaming doesn't work with native bindings."));
18+
return $p.reject(new Error("Streaming doesn't work with Native Bindings."));
1919
}
2020
if (!$npm.utils.isObject(qs, ['state', '_reading'])) {
2121
// stream object wasn't passed in correctly;
@@ -31,6 +31,7 @@ function $stream(ctx, qs, initCB, config) {
3131
}
3232
var error = $npm.events.query(ctx.options, getContext());
3333
if (error) {
34+
error = getError(error);
3435
$npm.events.error(ctx.options, error, getContext());
3536
return $p.reject(error);
3637
}
@@ -43,10 +44,10 @@ function $stream(ctx, qs, initCB, config) {
4344
if (!err && rows.length) {
4445
nRows += rows.length;
4546
var context = getContext();
46-
if (error === undefined) {
47+
if (!error) {
4748
error = $npm.events.receive(ctx.options, rows, undefined, context);
4849
}
49-
if (error !== undefined) {
50+
if (error) {
5051
stream.close();
5152
}
5253
}
@@ -61,6 +62,7 @@ function $stream(ctx, qs, initCB, config) {
6162
if (error) {
6263
// error thrown by initCB();
6364
stream._fetch = fetch;
65+
error = getError(error);
6466
$npm.events.error(ctx.options, error, getContext());
6567
return $p.reject(error);
6668
}
@@ -81,14 +83,16 @@ function $stream(ctx, qs, initCB, config) {
8183
onError(err);
8284
});
8385
function onError(e) {
84-
if (e instanceof $npm.utils.InternalError) {
85-
e = e.error;
86-
}
86+
e = getError(e);
8787
$npm.events.error(ctx.options, e, getContext());
8888
reject(e);
8989
}
9090
});
9191

92+
function getError(e) {
93+
return e instanceof $npm.utils.InternalError ? e.error : e;
94+
}
95+
9296
function getContext() {
9397
var client;
9498
if (ctx.db) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pg-promise",
3-
"version": "4.7.8",
3+
"version": "4.8.0",
44
"description": "Promises interface for PostgreSQL",
55
"main": "lib/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)