ley: Errors are swallowed

Hi, thanks for this tool!

I’ve noticed that DB connection errors using https://github.com/porsager/postgres are swallowed. It doesn’t show anything at all.

I need to add console.log(err) to this line https://github.com/lukeed/ley/blob/master/index.js#L42 in order to see the actual error.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (5 by maintainers)

Most upvoted comments

Ok, so I’ve gotten to the core of the issue now. There was actually two issues in Postgres.js which I’ve got fixed by investigating this, so thanks a lot for bringing it to my attention @frandiox and @lukeed !

The first was that I was wrongly expecting the socket to be ready before calling end() to try and end it gracefully, but it would never reach the ready state with things like connection errors.

The other was that I was using socket.end(resolve) for the end promise which would result in the promise returned by sql.end() being pending forever if something held the tcp connection open. For this use case it was better to use socket.on('close', resolve); socket.end() instead.

The reason your fix worked for this specific case was not because of rethrowing the error (which didn’t make sense to me at first), but because of removing arrayTypesPromise = null. That prevented the error popping up in the sql.end() and thereby hiding the above underlying issues.

I’ve released fixes for those issues in beta.2 now so I think this issue can also be closed 🙂

Thanks for hosting a Postgres.js issue here @lukeed 😂