ts-safeql / safeql

Validate and auto-generate TypeScript types from raw SQL queries in PostgreSQL.
https://safeql.dev
MIT License
1.35k stars 22 forks source link

Windows + `libpg-query@16.2.0`: SafeQL crashes with error code 127, error code 3221226505 #243

Open ProchaLu opened 4 months ago

ProchaLu commented 4 months ago

Describe the bug SafeQL throws wrong errors with libpg-query@16.2.0 on Windows and MacOS.

Issue also reported in VSCode ESlint repo:

Misleading errors:

Screenshot 2024-07-12 at 16 35 46

On macOS ESlint throws these errors:

➜  safeql-eslint-broken git:(main) ✗ pnpm eslint . --max-warnings 0
(node:48991) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Warning: React version was set to "detect" in eslint-plugin-react settings, but the "react" package is not installed. Assuming latest React version for linting.
Pages directory cannot be found at /Users/lukas/Documents/UpLeveled/safeql-eslint-broken/pages or /Users/lukas/Documents/UpLeveled/safeql-eslint-broken/src/pages. If using a custom path, please configure with the `no-html-link-for-pages` rule in your eslint config file.

/Users/lukas/Documents/UpLeveled/safeql-eslint-broken/database.ts
  13:0  error  Invalid Query: Error: syntax error at or near "."  @ts-safeql/check-sql
  35:0  error  Invalid Query: Error: syntax error at or near "{"  @ts-safeql/check-sql

On Windows ESlint throws an error code 127 "command not found"

$ pnpm eslint . --max-warnings 0
(node:11440) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
$ echo $?
127

On Windows with these issues, the ESLint VSCode extension crashes after 5 times in 3 minutes

Screenshot 2024-07-09 141747

To Reproduce

  1. Clone repo git clone https://github.com/ProchaLu/safeql-eslint-broken
  2. set .env variables
  3. migrate up
  4. Check the code and errors in the database.ts file

Expected behavior The expected behavior would be that SafeQL throws correct errors.

OS: Windows PostgreSQL version 15.7

karlhorky commented 2 months ago

Using the research strategy from issue #261, I've decoded the error code 3221226505 to the hex code 0xC0000409, which is more googlable.

How do you diagnose the exception code 0xc0000409 on Windows? | Stack Overflow

0xc0000409 means STATUS_STACK_BUFFER_OVERRUN.

In other words, something in your program is writing past the current stack frame, corrupting data on the stack. The program has detected this and rather than let it continue, has thrown an exception.

karlhorky commented 2 months ago

I've also reported this in a new libpg-query issue, to surface the crashes over there too: