swagger-api / swagger-api/swagger-codegen

Swagger Codegen CLI swallows RuntimeException, always returns success (0) exit code.

Open
#11,085 4 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Swagger Codegen CLI is swallowing all RuntimeExceptions thrown throughout the tool, and returns a success exit status (0). This makes it impossible to determine if errors occurred on our CI jobs while generating code.

https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/Codegen.java#L109-L120

Swagger-codegen version

3.0.20

current HEAD of 3.0.0 branch.

Swagger declaration file content or url

Any spec - simply use an invalid handlebar template to trigger a RuntimeException.

Command line used for generation
java -classpath <swagger jars> -l swift -i <my.yaml> -o <anywhere> -c <my-configuration.json>
Steps to reproduce

Simply use invalid handlebar template to trigger a RuntimeException, run the tool, and then run the following (zsh example)

echo $?

It will print 0 even though runtime exception occurred.

Related issues/PRs

The following appear to have same or similar root cause:

10434, 6832, 1140

Suggest a fix/enhancement

At these lines here, where swallowing Exception, simply add:

System.exit(<Error code, greater than 0, that identifies an error occurred>)

https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/Codegen.java#L109-L120

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at modules/swagger-codegen/src/main/java/io/swagger/codegen/Codegen.java, especially lines 109-120 where the RuntimeException is swallowed. Reproduce the failure with an invalid Handlebars template using the documented CLI command, then verify that echo $? reports a nonzero status when generation fails.

Written by the indexing model from the issue text.

Assessment

Tech stack
handlebars, java
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.