{"record":{"id":"7687a58d1048ae3f","repo":"kestra-io/kestra","slug":"the-nanoid-function-field-alphabet-must-not","errorCode":null,"errorMessage":"The 'nanoId()' function field 'alphabet' must not be empty","messagePattern":"The 'nanoId\\(\\)' function field 'alphabet' must not be empty","errorType":"exception","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/NanoIDFunction.java","lineNumber":37,"sourceCode":"    private static final String LENGTH = \"length\";\n    private static final String ALPHABET = \"alphabet\";\n\n    private static final int MAX_LENGTH = 1000;\n    private static final int MAX_ALPHABET_LENGTH = 256;\n\n    @Override\n    public Object execute(\n        Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) {\n        int length = DEFAULT_LENGTH;\n        if (args.containsKey(LENGTH) && (args.get(LENGTH) instanceof Long)) {\n            length = parseLength(args, self, lineNumber);\n        }\n        char[] alphabet = DEFAULT_ALPHABET;\n        if (args.containsKey(ALPHABET) && (args.get(ALPHABET) instanceof String)) {\n            alphabet = ((String) args.get(ALPHABET)).toCharArray();\n        }\n        if (alphabet.length == 0) {\n            throw new PebbleException(\n                null,\n                \"The 'nanoId()' function field 'alphabet' must not be empty\",\n                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) {","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/NanoIDFunction.java#L19-L55","documentation":"The nanoId(length, alphabet) function validates that the custom alphabet, if provided, is non-empty. The default alphabet is 64 URL-safe characters. If a user explicitly passes alphabet='' (empty string), it overrides the default and the resulting char array has length 0, triggering this error. A blank string with content does NOT trigger this because only an empty string produces a zero-length array.","triggerScenarios":"Calling {{ nanoId(alphabet='') }} with an explicitly empty alphabet string. A dynamic variable for the alphabet resolves to an empty string at runtime.","commonSituations":"The author sets alphabet from a variable that is conditionally populated and is empty in some code path. The author copies a template and forgets to fill in the alphabet value.","solutions":["Provide a non-empty alphabet: {{ nanoId(alphabet='ABCDEF0123456789') }}.","If you want the default alphabet, omit the alphabet argument entirely.","Ensure any dynamic variable used for the alphabet is never an empty string."],"exampleFix":"# before\nvalue: \"{{ nanoId(alphabet='') }}\"\n# after\nvalue: \"{{ nanoId(alphabet='ABCDEF0123456789') }}\"","handlingStrategy":"validation","validationCode":"# Ensure alphabet is non-empty, or omit it for the default:\n{% if myAlphabet is not empty %}\n  {{ nanoId(alphabet=myAlphabet) }}\n{% else %}\n  {{ nanoId() }}\n{% endif %}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Omit the alphabet argument to use the default 64-character URL-safe set.","Validate dynamic alphabet variables are non-empty before passing.","Use a fixed, well-defined alphabet string rather than a computed one."],"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"}