Skip to content
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

sql.begin() : UnhandledPromiseRejectionWarning #162

Closed
throrin19 opened this issue Mar 22, 2021 · 2 comments
Closed

sql.begin() : UnhandledPromiseRejectionWarning #162

throrin19 opened this issue Mar 22, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@throrin19
Copy link

throrin19 commented Mar 22, 2021

If sql.begin is called and throw error (database not reachable, impossible to connect, ...), the error is not able to be captured by try/catch.

Example : I try to run this sql script but the sql server is not available (I don't run the service) :

try {
    const sql = postgres(config);

    await sql.begin(async (sql) => {
        await sql`insert into test (label, value) values (${measure.label}, ${measure.value})`
    });

    await sql.end();
} catch (err) {
    console.log('error catched');
    console.error(err);
}

Code inside sql.begin and after it is never called and the catch part is never called. Otherwise we got this nodeJS error :

(node:13328) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:5432
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
(node:13328) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)

Informations

  • Node.js version : 14.15.4
  • postgres version : 1.0.2
@porsager
Copy link
Owner

Hi Thorin.

Thanks for the report.

Would you mind checking with postgres@beta ?

If that works we could backport the fix.

@porsager
Copy link
Owner

Ok, I just tested myself, and the issue is also present on master. I'll look into it.

@porsager porsager added the bug Something isn't working label Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants