Skip to content

TypeError: Cannot set property message of #<_ErrorEvent> which has only a getter on connection timeout with @neondatabase/serverless library #3373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andyjy opened this issue Feb 10, 2025 · 0 comments · Fixed by #3374

Comments

@andyjy
Copy link
Contributor

andyjy commented Feb 10, 2025

Using @neondatabase/serverless (which extends pg Client and Pool) I encountered the following fatal error thrown within pg-pool:

TypeError: Cannot set property message of #<_ErrorEvent> which has only a getter

This occurs since the exception passed to the connection callback for Pool is of type ErrorEvent (from the Cloudflare Workers websocket implementation) instead of Error, and ErrorEvent has a readonly message property that can't be overwritten.

While a fix could be written into @neondatabase/serverless to only pass an Error as pg-pool currently expects, it seemed more useful to address this here in pg-pool to be tolerant of different types for the exception in general, while preserving the original error message instead of overwriting it as per the current implementation.

Here is the diff that solved my problem:

diff --git a/node_modules/pg-pool/index.js b/node_modules/pg-pool/index.js
index 94004e0..52c595a 100644
--- a/node_modules/pg-pool/index.js
+++ b/node_modules/pg-pool/index.js
@@ -244,7 +244,7 @@ class Pool extends EventEmitter {
         // remove the dead client from our list of clients
         this._clients = this._clients.filter((c) => c !== client)
         if (timeoutHit) {
-          err.message = 'Connection terminated due to connection timeout'
+          err = new Error('Connection terminated due to connection timeout', { cause: err });
         }
 
         // this client won’t be released, so move on immediately

This issue body was partially generated by patch-package.

andyjy added a commit to andyjy/node-postgres that referenced this issue Feb 10, 2025
@andyjy andyjy changed the title Fatal error TypeError: Cannot set property message of #<_ErrorEvent> which has only a getter on connection timeout with @neondatabase/serverless library TypeError: Cannot set property message of #<_ErrorEvent> which has only a getter on connection timeout with @neondatabase/serverless library Feb 10, 2025
@brianc brianc closed this as completed in 95bec69 Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant