{"record":{"id":"5534fa58c6dceaa7","repo":"kestra-io/kestra","slug":"the-nanoid-function-field-length-must-be-gre","errorCode":null,"errorMessage":"The 'nanoId()' function field 'length' must be greater than: 0","messagePattern":"The 'nanoId\\(\\)' function field 'length' must be greater than: 0","errorType":"exception","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/NanoIDFunction.java","lineNumber":58,"sourceCode":"                lineNumber,\n                self.getName()\n            );\n        }\n        if (alphabet.length > MAX_ALPHABET_LENGTH) {\n            throw new PebbleException(\n                null,\n                \"The 'nanoId()' function field 'alphabet' must not contain more than: \" + MAX_ALPHABET_LENGTH + \" characters\",\n                lineNumber,\n                self.getName()\n            );\n        }\n        return createNanoID(length, alphabet);\n    }\n\n    private static int parseLength(Map<String, Object> args, PebbleTemplate self, int lineNumber) {\n        var value = (Long) args.get(LENGTH);\n        if (value < 1) {\n            throw new PebbleException(\n                null,\n                \"The 'nanoId()' function field 'length' must be greater than: 0\",\n                lineNumber,\n                self.getName()\n            );\n        }\n        if (value > MAX_LENGTH) {\n            throw new PebbleException(\n                null,\n                \"The 'nanoId()' function field 'length' must be lower than: \" + MAX_LENGTH,\n                lineNumber,\n                self.getName()\n            );\n        }\n        return Math.toIntExact(value);\n    }\n\n    @Override","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/NanoIDFunction.java#L40-L76","documentation":"The nanoId() function validates that the length argument, if provided, is at least 1. A length of 0 or a negative number triggers this error. The default length is 21 if no length argument is given. Note that this check only fires when the length argument is present and is a Long (Pebble numeric literals are Long).","triggerScenarios":"Calling {{ nanoId(length=0) }} or {{ nanoId(length=-5) }}. Passing a dynamic variable for length that resolves to 0 or a negative number.","commonSituations":"The author sets length from a variable that is conditionally computed and can be 0 in edge cases. The author misunderstands the function and passes 0 expecting a 'default' length.","solutions":["Provide a length of at least 1: {{ nanoId(length=8) }}.","Omit the length argument to use the default of 21.","Guard dynamic length values: {% if myLen > 0 %}{{ nanoId(length=myLen) }}{% else %}{{ nanoId() }}{% endif %}."],"exampleFix":"# before\nvalue: \"{{ nanoId(length=0) }}\"\n# after\nvalue: \"{{ nanoId(length=8) }}\"","handlingStrategy":"validation","validationCode":"# Ensure length is at least 1, or omit it for the default of 21:\n{% if myLength is not null and myLength > 0 %}\n  {{ nanoId(length=myLength) }}\n{% else %}\n  {{ nanoId() }}\n{% endif %}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Omit the length argument to use the default of 21.","Validate dynamic length variables are positive integers.","Guard against zero-length edge cases in conditional logic."],"tags":["pebble-function","nanoid","validation"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}