Skip to content

Commit 46e9317

Browse files
Only throw "filesystem unsupported" if the fs require fails
1 parent 78bb6b6 commit 46e9317

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

packages/pg-connection-string/index.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,26 @@ function parse(str) {
6868
config.ssl = {}
6969
}
7070

71-
try {
72-
if (config.sslcert) {
73-
const fs = require('fs')
74-
config.ssl.cert = fs.readFileSync(config.sslcert).toString()
71+
let fs
72+
if (config.sslcert || config.sslkey || config.sslrootcert) {
73+
try {
74+
// Only try to load fs if we expect to read from the disk
75+
fs = require('fs')
76+
} catch (e) {
77+
throw new Error('filesystem not supported')
7578
}
79+
}
7680

77-
if (config.sslkey) {
78-
const fs = require('fs')
79-
config.ssl.key = fs.readFileSync(config.sslkey).toString()
80-
}
81+
if (config.sslcert) {
82+
config.ssl.cert = fs.readFileSync(config.sslcert).toString()
83+
}
8184

82-
if (config.sslrootcert) {
83-
const fs = require('fs')
84-
config.ssl.ca = fs.readFileSync(config.sslrootcert).toString()
85-
}
86-
} catch (e) {
87-
throw new Error('filesystem not supported')
85+
if (config.sslkey) {
86+
config.ssl.key = fs.readFileSync(config.sslkey).toString()
87+
}
88+
89+
if (config.sslrootcert) {
90+
config.ssl.ca = fs.readFileSync(config.sslrootcert).toString()
8891
}
8992

9093
switch (config.sslmode) {

0 commit comments

Comments
 (0)