{"record":{"id":"aea5924c6763aa2c","repo":"OpenAPITools/openapi-generator","slug":"unable-to-build-target-e-getmessage","errorCode":null,"errorMessage":"Unable to build target: \" + e.getMessage()","messagePattern":"Unable to build target: \" \\+ e\\.getMessage\\(\\)","errorType":"http","errorClass":"ResponseStatusException","httpStatus":400,"severity":"error","filePath":"modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/Generator.java","lineNumber":175,"sourceCode":"                zip.compressFiles(filesToAdd, outputFilename);\n            } else {\n                throw new ResponseStatusException(HttpStatus.BAD_REQUEST,\n                        \"A target generation was attempted, but no files were created!\");\n            }\n            for (File file : files) {\n                try {\n                    file.delete();\n                } catch (Exception e) {\n                    LOGGER.error(\"unable to delete file \" + file.getAbsolutePath(), e);\n                }\n            }\n            try {\n                new File(outputFolder).delete();\n            } catch (Exception e) {\n                LOGGER.error(\"unable to delete output folder \" + outputFolder, e);\n            }\n        } catch (Exception e) {\n            throw new ResponseStatusException(HttpStatus.BAD_REQUEST, \"Unable to build target: \" + e.getMessage(), e);\n        }\n        return outputFilename;\n    }\n\n    private static File getTmpFolder() {\n        try {\n            File outputFolder = Files.createTempDirectory(\"codegen-tmp\").toFile();\n            outputFolder.deleteOnExit();\n            return outputFolder;\n        } catch (Exception e) {\n            e.printStackTrace();\n            throw new RuntimeException(\"Cannot access tmp folder\");\n        }\n    }\n}\n","sourceCodeStart":157,"sourceCodeEnd":191,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/Generator.java#L157-L191","documentation":"The catch-all around DefaultGenerator().generate() and ZipUtil.compressFiles (Generator.java:174-176): any exception during template processing, option application, or zipping is rethrown as 400 'Unable to build target: <original message>'. This is the most common failure of the generate endpoints and intentionally leaks the underlying cause text, which is your only diagnostic. The underlying exception ranges from invalid option values to NPEs inside individual generator templates.","triggerScenarios":"Invalid option values (e.g. non-numeric string for a numeric option, bad artifactId/packageName format); specs with semantic problems (duplicate operationIds, invalid names for the target language); generator-specific template exceptions; missing required option for a given generator; zipping failing because the tmp disk is full.","commonSituations":"Passing CLI-style options verbatim ('--artifactId=x' instead of {\"artifactId\":\"x\"}); specs that validate but break one specific generator; version skew between spec features and generator support; self-hosted servers with truncated classpaths throwing inside template code.","solutions":["Read the text after 'Unable to build target:' — it names the real exception and is the fastest route to the fix","Validate option keys/values against GET /api/gen/clients/{language}/options (types, enums, defaults) before posting","Reproduce locally with the openapi-generator CLI of the same version to iterate faster on the same inputs","For spec-semantic complaints (operationIds, naming), fix the spec; for template/NPE errors, try another generator or file an issue with the exact message"],"exampleFix":"# before: fire-and-forget POST, message lost\ncurl -s -X POST \"$host/api/gen/clients/java\" -H 'Content-Type: application/json' -d @req.json > /dev/null\n\n# after: surface the embedded cause\nresp=$(curl -s -w '\\n%{http_code}' -X POST \"$host/api/gen/clients/java\" \\\n  -H 'Content-Type: application/json' -d @req.json)\nstatus=$(echo \"$resp\" | tail -1)\n[ \"$status\" != 200 ] && { echo \"$resp\" | head -n -1; exit 1; }   # prints Unable to build target: <cause>","handlingStrategy":"try-catch","validationCode":"// pre-check option names and value types against the generator's own catalog\nMap<String, CliOption> catalog = restTemplate.getForObject(\n    host + \"/api/gen/clients/{l}/options\", new ParameterizedTypeReference<>() {}, language);\nfor (Map.Entry<String, Object> kv : desiredOptions.entrySet()) {\n    CliOption o = catalog.get(kv.getKey());\n    if (o == null) throw new IllegalArgumentException(\"unknown option \" + kv.getKey());\n    if (o.getEnum() != null && !o.getEnum().contains(String.valueOf(kv.getValue())))\n        throw new IllegalArgumentException(kv.getKey() + \" must be one of \" + o.getEnum());\n}","typeGuard":null,"tryCatchPattern":"catch (HttpClientErrorException.BadRequest e) {\n    String body = e.getResponseBodyAsString();\n    if (body.contains(\"Unable to build target\")) {\n        // the tail after the colon is the real generator exception — log it verbatim\n        log.error(\"generation failed: {}\", body.substring(body.indexOf(':') + 1).trim());\n    }\n}","preventionTips":["Always log the full response body — the embedded cause message is the diagnosis","Validate options against GET .../options (names, types, enums) before posting","Reproduce with the matching openapi-generator CLI locally to iterate on spec fixes"],"tags":["http-400","code-generation","catch-all","template-engine","openapi-generator-online"],"backgroundTag":"code-generation-failed","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}