Skip to content

Generator exit codes and error messages are not propagated on windows #10270

Open
RobertCraigie/prisma-client-py
#508

Description

@RobertCraigie

Bug description

On windows, if generator errors are not explicitly caught and returned (through JSONRPC) then the CLI process exits with 0 regardless of the state of the generator process and does not display any error message.

This behaviour is different on UNIX platforms, the Prisma CLI will exit with a non-zero code when a generator process errors.

How to reproduce

Run prisma generate:

(.venv) PS C:\Users\robert> prisma generate
Prisma schema loaded from schema.prisma
(.venv) PS C:\Users\robert> echo $LASTEXITCODE
0
Expand to show DEBUG logs
(.venv) PS C:\Users\robert> prisma generate
  prisma:tryLoadEnv Environment variables not found at null +0ms
  prisma:tryLoadEnv Environment variables not found at undefined +1ms
  prisma:tryLoadEnv No Environment variables loaded +0ms
  prisma:engines binaries to download query-engine, migration-engine, introspection-engine, prisma-fmt +0ms
  prisma:download Using env var PRISMA_QUERY_ENGINE_BINARY for binary query-engine, which points to C:\Users\rober\AppData\Local\Temp\prisma\binaries\engines\1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85\prisma-query-engine-windows.exe +0ms
  prisma:download Using env var PRISMA_MIGRATION_ENGINE_BINARY for binary migration-engine, which points to C:\Users\rober\AppData\Local\Temp\prisma\binaries\engines\1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85\prisma-migration-engine-windows.exe +0ms
  prisma:download Using env var PRISMA_INTROSPECTION_ENGINE_BINARY for binary introspection-engine, which points to C:\Users\rober\AppData\Local\Temp\prisma\binaries\engines\1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85\prisma-introspection-engine-windows.exe +0ms
  prisma:download Using env var PRISMA_FMT_BINARY for binary prisma-fmt, which points to C:\Users\rober\AppData\Local\Temp\prisma\binaries\engines\1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85\prisma-prisma-fmt-windows.exe +1ms
Prisma schema loaded from schema.prisma
  prisma:download Using env var PRISMA_QUERY_ENGINE_BINARY for binary query-engine, which points to C:\Users\rober\AppData\Local\Temp\prisma\binaries\engines\1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85\prisma-query-engine-windows.exe +0ms
  prisma:getConfig Using CLI Query Engine (Binary) at: C:\Users\rober\AppData\Local\Temp\prisma\binaries\engines\1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85\prisma-query-engine-windows.exe +0ms
  prisma:getDMMF Using CLI Query Engine (Binary) at: C:\Users\rober\AppData\Local\Temp\prisma\binaries\engines\1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85\prisma-query-engine-windows.exe +0ms
  prisma:getGenerators neededVersions {} +0ms
  prisma:GeneratorProcess Traceback (most recent call last): +0ms
  prisma:GeneratorProcess   File "C:\Python39\lib\runpy.py", line 197, in _run_module_as_main +0ms
  prisma:GeneratorProcess     return _run_code(code, main_globals, None, +1ms
  prisma:GeneratorProcess   File "C:\Python39\lib\runpy.py", line 87, in _run_code +0ms
  prisma:GeneratorProcess     exec(code, run_globals) +1ms
  prisma:GeneratorProcess   File "C:\Users\rober\.venv\Scripts\prisma-client-py.exe\__main__.py", line 7, in <module> +0ms
  prisma:GeneratorProcess   File "c:\users\rober\.venv\lib\site-packages\prisma\cli\cli.py", line 50, in main +1ms
  prisma:GeneratorProcess     prisma.invoke() +0ms
  prisma:GeneratorProcess   File "c:\users\rober\.venv\lib\site-packages\prisma\cli\prisma.py", line 93, in invoke +0ms
  prisma:GeneratorProcess     generator.run(request.params) +1ms
  prisma:GeneratorProcess   File "c:\users\rober\.venv\lib\site-packages\prisma\generator\generator.py", line 71, in run +0ms
  prisma:GeneratorProcess     render_template(rootdir, name, params) +0ms
  prisma:GeneratorProcess   File "c:\users\rober\.venv\lib\site-packages\prisma\generator\generator.py", line 118, in render_template +1ms
  prisma:GeneratorProcess     output = template.render(**params) +0ms
  prisma:GeneratorProcess   File "c:\users\rober\.venv\lib\site-packages\jinja2\environment.py", line 1291, in render +0ms
  prisma:GeneratorProcess     self.environment.handle_exception() +1ms
  prisma:GeneratorProcess   File "c:\users\rober\.venv\lib\site-packages\jinja2\environment.py", line 925, in handle_exception +0ms
  prisma:GeneratorProcess     raise rewrite_traceback_stack(source=source) +0ms
  prisma:GeneratorProcess   File "c:\users\rober\.venv\lib\site-packages\prisma\generator\templates\types.py.jinja", line 318, in top-level template code +1ms
  prisma:GeneratorProcess     {{'    '}}{{ field.name }}: {{ field.maybe_optional(field.get_update_input_type()) }} +0ms
  prisma:GeneratorProcess   File "c:\users\rober\.venv\lib\site-packages\prisma\generator\models.py", line 506, in get_update_input_type +1ms
  prisma:GeneratorProcess     raise NotImplementedError( +0ms
  prisma:GeneratorProcess NotImplementedError: Atomic updates for scalar list types not implemented yet. +0ms

Expected behavior

An error message should be displayed and the process should exit with a non-zero code.

Prisma information

datasource db {
    provider = "postgres"
    url      = env("DATABASE_URL")
}

generator db {
    provider             = "prisma-client-py"
    interface            = "asyncio"
    recursive_type_depth = -1
}

model User {
    id      String @id @default(cuid())
    name    String
    numbers Int[]
}

Environment & setup

  • OS: Windows 10
  • Database: PostgreSQL
  • Node.js version: N/A

Prisma Version

prisma                : 3.4.0
@prisma/client        : Not found
Current platform      : windows
Query Engine (Binary) : query-engine 1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85 (at AppData\Local\Temp\prisma\binaries\engines\1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85\prisma-query-engine-windows.exe, resolved by PRISMA_QUERY_ENGINE_BINARY)
Migration Engine      : migration-engine-cli 1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85 (at AppData\Local\Temp\prisma\binaries\engines\1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85\prisma-migration-engine-windows.exe, resolved by PRISMA_MIGRATION_ENGINE_BINARY)
Introspection Engine  : introspection-core 1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85 (at AppData\Local\Temp\prisma\binaries\engines\1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85\prisma-introspection-engine-windows.exe, resolved by PRISMA_INTROSPECTION_ENGINE_BINARY)
Format Binary         : prisma-fmt 1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85 (at AppData\Local\Temp\prisma\binaries\engines\1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85\prisma-prisma-fmt-windows.exe, resolved by PRISMA_FMT_BINARY)
Default Engines Hash  : 1c9fdaa9e2319b814822d6dbfd0a69e1fcc13a85

Activity

  1. changed the title [-]Generator exit codes and errors are not propagated on windows[/-] [+]Generator exit codes and error messages are not propagated on windows[/+] on Nov 15, 2021
  2. added
    bug/0-unknown
    topic: prisma generate
    on Nov 19, 2021
  3. janpio commented on Nov 19, 2021

    @janpio
    Contributor

    Does this apply to all generators or "just" to custom generators?

  4. RobertCraigie commented on Nov 19, 2021

    @RobertCraigie
    Author

    I'm not sure, I did not test it with other generators and do not have access to a windows machine at the moment. Will update as soon as possible.

    Although I am fairly certain that this issue won't occur with any JavaScript based generators as errors are explicitly sent back to the Prisma CLI through JSON-RPC (the prisma-client-py JSON-RPC implementation does not do this yet) and a while ago I was experimenting with generator exit codes and found that if the process crashed before starting the JSON-RPC generation loop then the error was correctly propagated.

    The example I used above crashes during the generate call of the JSON-RPC generation loop.

    I could be totally misremembering though, it has been a while since I experimented with Prisma on windows.

  5. RobertCraigie commented on Nov 22, 2021

    @RobertCraigie
    Author

    @janpio Here's a minimal reproduction using a custom TS generator:

    https://github.com/RobertCraigie/prisma-reproduction-10270

    $ npm install
    ...
    
    $ npx prisma generate
    Environment variables loaded from .env
    Prisma schema loaded from prisma\schema.prisma
    
    > testing@ generator D:\testing\prisma
    > bad-ts-node src
    
    $ echo $LASTEXITCODE
    0
    
  6. added
    bug/1-unconfirmed
    and removed
    bug/0-unknown
    on Nov 22, 2021
  7. added
    bug/2-confirmed
    and removed
    bug/1-unconfirmed
    on Nov 30, 2021
  8. modified the milestone: 3.7.0 on Nov 30, 2021
  9. added
    tech/typescript
    on Dec 1, 2021
  10. added this to the 3.8.0 milestone on Dec 21, 2021
  11. reopened this on Oct 4, 2022
  12. aqrln commented on Oct 4, 2022

    @aqrln
    Member

    Reopening because, if my understanding of the issue is correct, the issue is still there in Prisma even if Prisma Client Python works around it now.

  13. RobertCraigie commented on Oct 5, 2022

    @RobertCraigie
    Author

    Ah yeah you're right, thanks!

    I didn't realise GitHub would automatically close issues across repositories when they're not in the same org.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/2-confirmedkind/bugtech/typescripttopic: prisma generatetopic: windows

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions