jhnnsrs / turms

Turms is a pure python implementation of the awesome graphql-codegen library, following a simliar extensible design.
https://jhnnsrs.github.io/turms/
MIT License
62 stars 16 forks source link

Incorrectly exit with 0 when generation failed #59

Closed yuliswe closed 1 year ago

yuliswe commented 1 year ago

My code contains a mismatched type, where a String! is used when it should be NonNegativeDecimal!. Code generation fails with the error message, but turms exits with code 0.

This causes the error to be not detectable in CI.

-------------- Generating project: default --------------
-------- ERROR FOR PROJECT: DEFAULT --------
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│                                                                                                  │
│ /Users/yu/lab/FastchargeAPI/.venv/lib/python3.9/site-packages/turms/run.py:328 in generate_ast   │
│                                                                                                  │
│   325 │                                                                                          │
│   326 │   for plugin in plugins:                                                                 │
│   327 │   │   try:                                                                               │
│ ❱ 328 │   │   │   global_tree += plugin.generate_ast(schema, config, registry)                   │
│   329 │   │   except Exception as e:                                                             │
│   330 │   │   │   raise GenerationError(f"Plugin:{plugin} failed!") from e                       │
│   331                                                                                            │
│ /Users/yu/lab/FastchargeAPI/.venv/lib/python3.9/site-packages/turms/plugins/fragments.py:310 in  │
│ generate_ast                                                                                     │
│                                                                                                  │
│   307 │   │                                                                                      │
│   308 │   │   plugin_tree = []                                                                   │
│   309 │   │                                                                                      │
│ ❱ 310 │   │   documents = parse_documents(                                                       │
│   311 │   │   │   client_schema, self.config.fragments_glob or config.documents                  │
│   312 │   │   )                                                                                  │
│   313                                                                                            │
│                                                                                                  │
│ /Users/yu/lab/FastchargeAPI/.venv/lib/python3.9/site-packages/turms/utils.py:273 in              │
│ parse_documents                                                                                  │
│                                                                                                  │
│   270 │                                                                                          │
│   271 │   errors = validate(client_schema, nodes)                                                │
│   272 │   if len(errors) > 0:                                                                    │
│ ❱ 273 │   │   raise Exception(errors)                                                            │
│   274 │                                                                                          │
│   275 │   return nodes                                                                           │
│   276                                                                                            │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
Exception: [GraphQLError("Variable '$minMonthlyCharge' of type 'String!' used in position expecting type 'NonNegativeDecimal!'.", 
locations=[SourceLocation(line=210, column=5), SourceLocation(line=220, column=27)]), GraphQLError("Variable '$chargePerRequest' of type 'String!' used in
position expecting type 'NonNegativeDecimal!'.", locations=[SourceLocation(line=211, column=5), SourceLocation(line=221, column=27)])]

The above exception was the direct cause of the following exception:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│                                                                                                  │
│ /Users/yu/lab/FastchargeAPI/.venv/lib/python3.9/site-packages/turms/run.py:186 in gen            │
│                                                                                                  │
│   183 │   │   │   │   f"-------------- Generating project: {key} --------------"                 │
│   184 │   │   │   )                                                                              │
│   185 │   │   │                                                                                  │
│ ❱ 186 │   │   │   generated_code = generate(project)                                             │
│   187 │   │   │                                                                                  │
│   188 │   │   │   write_code_to_file(                                                            │
│   189 │   │   │   │   generated_code,                                                            │
│ /Users/yu/lab/FastchargeAPI/.venv/lib/python3.9/site-packages/turms/run.py:278 in generate       │
│                                                                                                  │
│   275 │   │   │   get_console().print(f"Using Processor {styler}")                               │
│   276 │   │   processors.append(styler)                                                          │
│   277 │                                                                                          │
│ ❱ 278 │   generated_ast = generate_ast(                                                          │
│   279 │   │   gen_config,                                                                        │
│   280 │   │   schema,                                                                            │
│   281 │   │   plugins=plugins,                                                                   │
│                                                                                                  │
│ /Users/yu/lab/FastchargeAPI/.venv/lib/python3.9/site-packages/turms/run.py:330 in generate_ast   │
│                                                                                                  │
│   327 │   │   try:                                                                               │
│   328 │   │   │   global_tree += plugin.generate_ast(schema, config, registry)                   │
│   329 │   │   except Exception as e:                                                             │
│ ❱ 330 │   │   │   raise GenerationError(f"Plugin:{plugin} failed!") from e                       │
│   331 │                                                                                          │
│   332 │   global_tree = (                                                                        │
│   333 │   │   registry.generate_imports() + registry.generate_builtins() + global_tree           │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
GenerationError: Plugin:config=FragmentsPluginConfig(type='turms.plugins.fragments.FragmentsPlugin', fragment_bases=None, fragments_glob=None) failed!
jhnnsrs commented 1 year ago

Agreed, should result in 1. I didnt include it in the first place to not interfere when only one project fails to codegen, will include a "exit_on_error" value in the config for each project with a default set to true? How does that sound? Also it seems like your using a older version without the new rich-click cli? any reason for that? does it not run well in your scenario?

jhnnsrs commented 1 year ago

60 Should be fixing this issue :)

jhnnsrs commented 1 year ago

turms 0.4.2 fixes it ;)

yuliswe commented 1 year ago

Thank you!