Skip to content

Commit a519e18

Browse files
committed
Fetch os.username() optimistically - fixes porsager#51
1 parent 7a4ef4b commit a519e18

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ function parseOptions(a, b) {
490490
port,
491491
path : o.path || host.indexOf('/') > -1 && host + '/.s.PGSQL.' + port,
492492
database : o.database || o.db || (url.pathname || '').slice(1) || env.PGDATABASE || 'postgres',
493-
user : o.user || o.username || auth[0] || env.PGUSERNAME || env.PGUSER || os.userInfo().username,
493+
user : o.user || o.username || auth[0] || env.PGUSERNAME || env.PGUSER || osUsername(),
494494
pass : o.pass || o.password || auth[1] || env.PGPASSWORD || '',
495495
max : o.max || url.query.max || Math.max(1, os.cpus().length),
496496
types : o.types || {},
@@ -505,3 +505,11 @@ function parseOptions(a, b) {
505505
mergeUserTypes(o.types)
506506
)
507507
}
508+
509+
function osUsername() {
510+
try {
511+
return require('os').userInfo().username // eslint-disable-line
512+
} catch (_) {
513+
return
514+
}
515+
}

0 commit comments

Comments
 (0)