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 + Prisma: Server process exited with code 3765269347 #261

Open karlhorky opened 2 months ago

karlhorky commented 2 months ago

Originally reported by @Vishal-beep136 in https://github.com/ts-safeql/safeql/issues/255#issuecomment-2298060086

Original comment below:


Heyy I was able to install successfully @ts-safeql/eslint-plugin libpg-query without any errors however it doesn't seems to work, like it's not linting or showing error. I'm using it with Prisma.

I followed this doc prisma

const query = prisma.$queryRaw`SELECT idd FROM users`;

it should display error like -> Error: column "idd" does not exist

I'm not sure what went wrong I believe I've even configured it correct in .eslintrc.js

 module.exports = { 
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: 'tsconfig.json',
    tsconfigRootDir: __dirname,
    sourceType: 'module',
  },
  plugins: ['@typescript-eslint/eslint-plugin', '@ts-safeql/eslint-plugin'],
  rules: {
    ....
    '@ts-safeql/check-sql': [
      'error',
      {
        connections: [
          {
            connectionUrl: process.env.DATABASE_URL,
            migrationsDir: './prisma/migrations',
            targets: [
              { tag: 'prisma.+($queryRaw|$executeRaw)', transform: '{type}[]' },
            ],
          },
        ],
      },
    ],
  },
 }

also EsLint is crashing a lot

[Info  - 12:20:26 PM] ESLint server running in node v20.14.0
[Info  - 12:20:26 PM] ESLint server is running.
[Info  - 12:20:27 PM] ESLint library loaded from: D:\app\backend-nestjs\node_modules\eslint\lib\api.js
migrationPath D:\app\backend-nestjs\prisma\migrations
[Error - 12:20:39 PM] Server process exited with code 3765269347.
[Error - 12:20:39 PM] The ESLint server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
[Info  - 12:20:39 PM] ESLint server stopped.

Could be that @ts-safeql/eslint-plugin libpg-query aren't compatible with windows OS 😭 ?? or Am I missing something ??

Thanks :)

karlhorky commented 2 months ago

@Vishal-beep136

Research the error further

We can first try to find out what this error code 3765269347 means.

It appears that error code 3765269347 is also known as 0xE06D7363, which apparently means:

The diagnostic is that the DllMain() function inside the DLL died due to an unhandled C++ exception

So it appears there is an unhandled C++ exception somewhere in the Windows version of libpg-query, the code path of which is triggered by SafeQL, causing a crash.

Try a more minimal setup

One thing that I would do in your position is first try out your setup with more minimal code.

@ProchaLu also experienced SafeQL crashing on Windows (with a different error code, 3221226505), due to invalid SQL:

You can try to first only lint a single file on the command line:

npx eslint backend-nestjs/prisma/migrations/001-users.ts

If that doesn't fail with the same error message, then you can try to expand to other files until you identify which file is causing the problem.

Once you have identified which file is causing SafeQL to crash, then you can check the file contents to see if there is any unusual SQL in there.

Eg. in @ProchaLu's issue linked above, he identified 3 errors which caused crashes with SafeQL on Windows:

  1. missing comma (should be after users.id)
  2. curly brackets instead of parentheses (after ON)
  3. incorrect table name (user instead of users)

So if any of these (or similar) could apply to your situation, then this may explain the SafeQL crashes.

karlhorky commented 2 months ago

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