Skip to content

Commit ad2ffce

Browse files
langpavelbrianc
authored andcommitted
pg.native returns null if pg-native is missing (#950)
`require('pg').native` will be `null` and report error once to `stdout` when `pg-native` is missing.
1 parent 06743a7 commit ad2ffce

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/index.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,16 @@ if(typeof process.env.NODE_PG_FORCE_NATIVE != 'undefined') {
7575
//lazy require native module...the native module may not have installed
7676
module.exports.__defineGetter__("native", function() {
7777
delete module.exports.native;
78-
module.exports.native = new PG(require('./native'));
79-
return module.exports.native;
78+
var native = null;
79+
try {
80+
native = new PG(require('./native'));
81+
} catch (err) {
82+
if (err.code !== 'MODULE_NOT_FOUND') {
83+
throw err;
84+
}
85+
console.error(err.message);
86+
}
87+
module.exports.native = native;
88+
return native;
8089
});
8190
}

test/native/missing-native.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@
33

44
var assert = require('assert');
55

6-
assert.throws(function() {
7-
require('../../lib').native;
8-
});
6+
assert.equal(require('../../lib').native, null);

0 commit comments

Comments
 (0)