Skip to content

Commit

Permalink
Only throw "filesystem unsupported" if the fs require fails
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin committed May 5, 2023
1 parent 78bb6b6 commit 46e9317
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions packages/pg-connection-string/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,26 @@ function parse(str) {
config.ssl = {}
}

try {
if (config.sslcert) {
const fs = require('fs')
config.ssl.cert = fs.readFileSync(config.sslcert).toString()
let fs
if (config.sslcert || config.sslkey || config.sslrootcert) {
try {
// Only try to load fs if we expect to read from the disk
fs = require('fs')
} catch (e) {
throw new Error('filesystem not supported')
}
}

if (config.sslkey) {
const fs = require('fs')
config.ssl.key = fs.readFileSync(config.sslkey).toString()
}
if (config.sslcert) {
config.ssl.cert = fs.readFileSync(config.sslcert).toString()
}

if (config.sslrootcert) {
const fs = require('fs')
config.ssl.ca = fs.readFileSync(config.sslrootcert).toString()
}
} catch (e) {
throw new Error('filesystem not supported')
if (config.sslkey) {
config.ssl.key = fs.readFileSync(config.sslkey).toString()
}

if (config.sslrootcert) {
config.ssl.ca = fs.readFileSync(config.sslrootcert).toString()
}

switch (config.sslmode) {
Expand Down

0 comments on commit 46e9317

Please sign in to comment.