{"record":{"id":"21ad64090d1d486b","repo":"kestra-io/kestra","slug":"the-s-filter-expects-a-positive-integer-0-as","errorCode":null,"errorMessage":"The '%s' filter expects a positive integer >=0 as argument 'amount'.","messagePattern":"The '(.+?)' filter expects a positive integer >=0 as argument 'amount'\\.","errorType":"validation","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/AbstractIndent.java","lineNumber":56,"sourceCode":"\n        return System.lineSeparator(); // System default\n    }\n\n    protected Object abstractApply(Object input, Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber, String indentType) throws PebbleException {\n        if (input == null) {\n            return null;\n        }\n        if (input.toString().isEmpty()) {\n            return input.toString();\n        }\n\n        if (!args.containsKey(\"amount\")) {\n            throw new PebbleException(null, String.format(\"The '%s' filter expects an integer as argument 'amount'.\", indentType), lineNumber, self.getName());\n        }\n\n        int amount = ((Long) args.get(\"amount\")).intValue();\n        if (!(amount >= 0)) {\n            throw new PebbleException(null, String.format(\"The '%s' filter expects a positive integer >=0 as argument 'amount'.\", indentType), lineNumber, self.getName());\n        }\n\n        String prefix = prefix(args);\n        String newLine = getLineSeparator(input.toString());\n\n        if (indentType.equals(\"indent\"))\n            // indent filter adds N amount of spaces to each line except for the first one (assuming the first line is already indented in place)\n            return input.toString().replace(newLine, newLine + prefix.repeat(amount));\n        else if (indentType.equals(\"nindent\")) {\n            // nindent filter adds a newline to the string and indents each line by defined amount of spaces\n            return (newLine + input).replace(newLine, newLine + prefix.repeat(amount));\n        }\n        throw new PebbleException(null, String.format(\"Unknown indent type '%s'.\", indentType), lineNumber, self.getName());\n\n    }\n}\n","sourceCodeStart":38,"sourceCodeEnd":73,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/AbstractIndent.java#L38-L73","documentation":"Thrown by AbstractIndent when the 'amount' argument of the indent or nindent filter is a negative number. The filter requires amount to be zero or positive because a negative repeat count for the prefix string is meaningless.","triggerScenarios":"Passing a negative integer to indent or nindent: '{{ text | indent(-2) }}'. Also possible when the amount comes from a variable or expression that evaluates to a negative value at runtime.","commonSituations":"A computed amount variable that underflows to negative due to subtraction or a malformed input. Hard-coding a negative value by mistake.","solutions":["Change the amount to zero or a positive integer: '{{ text | indent(0) }}' or '{{ text | indent(4) }}'.","If the amount is dynamic, clamp it with a max/min expression: '{{ text | indent(max(vars.indent, 0)) }}'.","Audit the upstream variable or expression that produces the negative value."],"exampleFix":"{# before #}\n{{ text | indent(vars.indent_level) }}\n{# where vars.indent_level = -1 #}\n\n{# after #}\n{{ text | indent(max(vars.indent_level, 0)) }}","handlingStrategy":"validation","validationCode":"{# Clamp the amount to a minimum of zero before passing it #}\n{% set safe_indent = max(vars.indent_amount ?? 0, 0) %}\n{{ text | indent(safe_indent) }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass a negative literal to indent or nindent.","When the amount is dynamic, clamp with max(value, 0).","Validate computed indent values in the upstream task before they reach the template."],"tags":["pebble","indent-filter","nindent-filter","invalid-argument"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}