{"record":{"id":"b864662ed509c714","repo":"kestra-io/kestra","slug":"s-can-t-be-converted-to-long","errorCode":null,"errorMessage":"%s can't be converted to long","messagePattern":"(.+?) can't be converted to long","errorType":"validation","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/filters/DateAddFilter.java","lineNumber":52,"sourceCode":"        ZonedDateTime date = convert(input, zoneId, existingFormat);\n\n        ZonedDateTime plus = date.plus(amount, ChronoUnit.valueOf(unit));\n\n        return format(plus, args, context);\n    }\n\n    public static Long getAsLong(Object value, int lineNumber, PebbleTemplate self) {\n        if (value instanceof Long longValue) {\n            return longValue;\n        } else if (value instanceof Integer integerValue) {\n            return integerValue.longValue();\n        } else if (value instanceof Number numberValue) {\n            return numberValue.longValue();\n        } else if (value instanceof String stringValue) {\n            try {\n                return Long.parseLong(stringValue);\n            } catch (NumberFormatException e) {\n                throw new PebbleException(\n                    e, \"%s can't be converted to long\".formatted(stringValue),\n                    lineNumber, self != null ? self.getName() : \"Unknown\"\n                );\n            }\n        }\n        throw new PebbleException(\n            null, \"Incorrect %s format, must be a number\".formatted(value),\n            lineNumber, self != null ? self.getName() : \"Unknown\"\n        );\n    }\n\n}\n","sourceCodeStart":34,"sourceCodeEnd":65,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/filters/DateAddFilter.java#L34-L65","documentation":"Thrown by DateAddFilter.getAsLong when the 'amount' argument is a String that cannot be parsed as a Long via Long.parseLong. The filter accepts string amounts for flexibility but they must represent a valid integer; non-numeric strings cause a NumberFormatException that is caught and rethrown as this PebbleException.","triggerScenarios":"Passing a non-numeric string as the amount to the dateAdd filter: '{{ mydate | dateAdd(\"abc\", \"days\") }}', '{{ mydate | dateAdd(\"1.5\", \"hours\") }}' (decimal strings are rejected). The amount comes from a variable that resolves to a non-numeric string.","commonSituations":"User-provided duration values that include units or text instead of a plain number (e.g., \"2 days\" instead of \"2\"). Configuration that stores amounts as strings with formatting. Decimal values where only integers are accepted.","solutions":["Pass a bare integer or a numeric string without decimals: '{{ mydate | dateAdd(2, \"days\") }}'.","Strip non-numeric characters from the variable before passing it: parse or sanitize the upstream value.","Ensure the amount variable is typed as a number, not a free-text string."],"exampleFix":"{# before #}\n{{ execution.startDate | dateAdd(vars.offset, \"days\") }}\n{# vars.offset = \"two\" #}\n\n{# after #}\n{{ execution.startDate | dateAdd(2, \"days\") }}","handlingStrategy":"validation","validationCode":"{# Ensure amount is a valid integer string or number before dateAdd #}\n{% set amt = vars.offset ?? 0 %}\n{% if amt is numeric %}\n  {{ date | dateAdd(amt, \"days\") }}\n{% else %}\n  {{ date }}\n{% endif %}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass a bare integer for the amount argument to dateAdd.","If using a string variable, ensure it contains only digits (no units, no decimals).","Sanitize user-provided duration values to extract the numeric part before templating."],"tags":["pebble","dateadd-filter","type-mismatch","date"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}