{"record":{"id":"3a0eef1036078fdc","repo":"OpenAPITools/openapi-generator","slug":"cachescope-key-cannot-be-empty","errorCode":null,"errorMessage":"cacheScope key cannot be empty","messagePattern":"cacheScope key cannot be empty","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/CacheLambda.java","lineNumber":63,"sourceCode":"    public void execute(Fragment fragment, Writer writer) throws IOException {\n        String content = fragment.execute();\n\n        // Accept either \"key|content\" or a multiline form where the first line is the key.\n        int separatorIndex = content.indexOf('|');\n        if (separatorIndex < 0) {\n            int lineBreakIndex = findFirstLineBreakIndex(content);\n            if (lineBreakIndex >= 0) {\n                separatorIndex = lineBreakIndex;\n            }\n        }\n\n        if (separatorIndex < 0) {\n            throw new IllegalArgumentException(\"cacheScope requires 'key|content' or 'key\\\\ncontent'\");\n        }\n\n        String key = content.substring(0, separatorIndex).trim();\n        if (key.isEmpty()) {\n            throw new IllegalArgumentException(\"cacheScope key cannot be empty\");\n        }\n\n        int contentStartIndex = separatorIndex + 1;\n        // For CRLF, skip both '\\r' and '\\n'. For LF-only/CR-only, skip just one character.\n        if (separatorIndex < content.length() && content.charAt(separatorIndex) == '\\r') {\n            if (contentStartIndex < content.length() && content.charAt(contentStartIndex) == '\\n') {\n                contentStartIndex++;\n            }\n        }\n\n        this.cacheContent.contentByKey.put(key, content.substring(contentStartIndex));\n    }\n\n    private int findFirstLineBreakIndex(String content) {\n        // Keep this simple and cross-platform by checking all common line endings.\n        int unix = content.indexOf('\\n');\n        int windows = content.indexOf('\\r');\n","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/CacheLambda.java#L45-L81","documentation":"CacheLambda (the 'cache' mustache lambda used by C# generators) splits its body at the first '|' or line break; the part before it, trimmed, becomes the cache key. If that key part is empty — the body starts with '|' or the first line is blank/whitespace — an IllegalArgumentException is thrown because a recall later could never address the stored content. Like the missing-separator error, this fires at template render time.","triggerScenarios":"A template block {{#cache}}|some content{{/cache}} (leading pipe), or a multiline body whose first line is only spaces, e.g. {{#cache}}\\n  content{{/cache}} — the trimmed key is empty.","commonSituations":"Reformatting mustache templates with auto-indent that pushes the key onto its own blank line; copying a cached block and deleting its key but leaving the separator; template snippets from PRs where the key placeholder was never filled in.","solutions":["Put a non-empty key before the separator: {{#cache}}userModel|...content...{{/cache}}.","If using the multiline form, make the first line the key and start content on line two.","Lint cached blocks for a non-blank prefix before the first '|' or newline."],"exampleFix":"{{! before }}\n{{#cache}}|public partial class UserModel { }{{/cache}}\n\n{{! after }}\n{{#cache}}userModel|public partial class UserModel { }{{/cache}}","handlingStrategy":"validation","validationCode":"# lint: reject cache blocks whose key part (before '|' or newline) is empty/whitespace\ngrep -rnE '\\{\\{#cache\\}\\}(\\||[[:space:]]*(\\||$))' templates/ && {\n  echo \"ERROR: {{#cache}} key cannot be empty\" >&2; exit 1;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always write an explicit key before the '|' — never start the block with the separator.","Disable auto-indent/formatters on mustache templates, or re-lint after formatting."],"tags":["mustache","template","csharp","codegen","cache-lambda"],"backgroundTag":"mustache-lambda-template-error","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}