From 1b2bedc9c86b7378288e704252a8e4fafa27aa34 Mon Sep 17 00:00:00 2001 From: Mathias Bockwoldt Date: Mon, 28 Jul 2025 12:48:29 +0000 Subject: [PATCH] feat(pg-connection-string): throw correct error when URL parsing fails Fixes #3513 --- packages/pg-connection-string/index.js | 1 + packages/pg-connection-string/test/parse.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/pg-connection-string/index.js b/packages/pg-connection-string/index.js index 867256012..e34eabf4c 100644 --- a/packages/pg-connection-string/index.js +++ b/packages/pg-connection-string/index.js @@ -35,6 +35,7 @@ function parse(str, options = {}) { } catch (err) { // Remove the input from the error message to avoid leaking sensitive information err.input && (err.input = '*****REDACTED*****') + throw err } // We'd like to use Object.fromEntries() here but Node.js 10 does not support it diff --git a/packages/pg-connection-string/test/parse.ts b/packages/pg-connection-string/test/parse.ts index 1ba636788..a58edbe9c 100644 --- a/packages/pg-connection-string/test/parse.ts +++ b/packages/pg-connection-string/test/parse.ts @@ -330,6 +330,7 @@ describe('parse', function () { parse(connectionString) } catch (err: unknown) { expect(JSON.stringify(err)).to.not.include(password, 'Password should not be in the error message') + expect(JSON.stringify(err)).to.include('REDACTED', 'The thrown error should contain the redacted URL') return } throw new Error('Expected an error to be thrown')