Closed aslushnikov closed 3 months ago
Hi. Great error report! Thank you!
I think your expectations are correct, so that's quite the bug you've found here. I'll dig into it.
Ok, I found the issue. It was accidentally trying to use the routineRetry logic for simple queries (should only be used for prepared statements), which makes no sense, and messes with the protocol expectations for simple queries.
You can try it out by installing latest master using npm i porsager/postgres
Related to your issue 2, you have a stray "async" for your function. The function should look like this:
import postgres from 'postgres'
const sql = postgres({ max: 1 });
await sql.begin(sql => [
sql`
CREATE TABLE user_permissions (
permissions TEXT[] NOT NULL
)
`,
sql`
INSERT INTO user_permissions (permissions)
VALUES (('read', 'write', 'delete'))
`,
]);
await sql.end();
This is awesome, thank you for the quick fix!
You can try it out by installing latest master using npm i porsager/postgres
@porsager I just tried, but the issue still reproduces for me on tip-of-tree. I tried cloning & building the repository, but no luck!
Didn't transpile for cjs etc, so if you're not using the esm version that might be it. Just a sec 😊
Try again now 😉
If there's still an error, do post it 👍
Still no luck; here's the exact thing that I try: https://github.com/aslushnikov/postgres-js-issue-repro
To validate the repro, there's a commented-out node-postgres
code snippet that does throw an error:
To make sure this is not something specific to my machine, here are Github Actions running this test: https://github.com/aslushnikov/postgres-js-issue-repro/actions/runs/8364618788/job/22900381583
There we go :-) Single character mistake - sorry
@porsager awesome, it works now!
I had to build it manually since installation from GH doesn't work. That's not an issue for me though – i'll happily wait for the next release.
Thank you!
Hi! First and foremost, thank you for the pleasant and capable library!
Issue 1: swallowed errors from manual transactions
Let's say we have the following SQL file with a wrong
INSERT
statement (types of permissions mismatches the expected one):Trying to execute this file with
sql.file
silently swallows the error and pretends that everything is good.I'd expect the
sql.file
command to throw an error.Issue 2: swallowed errors from
sql.begin()
The following also doesn't throw any errors:
Appendix: when the error is correctly thrown
I found that only the following snippet actually throws an error in this case:
This throws the expected error:
Is this a known issue? Do I do something wrong?