kestra-io/kestra · error · PebbleException
%s can't be converted to long
Error message
%s can't be converted to long
What it means
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.
Source
Thrown at core/src/main/java/io/kestra/core/runners/pebble/filters/DateAddFilter.java:52
ZonedDateTime date = convert(input, zoneId, existingFormat);
ZonedDateTime plus = date.plus(amount, ChronoUnit.valueOf(unit));
return format(plus, args, context);
}
public static Long getAsLong(Object value, int lineNumber, PebbleTemplate self) {
if (value instanceof Long longValue) {
return longValue;
} else if (value instanceof Integer integerValue) {
return integerValue.longValue();
} else if (value instanceof Number numberValue) {
return numberValue.longValue();
} else if (value instanceof String stringValue) {
try {
return Long.parseLong(stringValue);
} catch (NumberFormatException e) {
throw new PebbleException(
e, "%s can't be converted to long".formatted(stringValue),
lineNumber, self != null ? self.getName() : "Unknown"
);
}
}
throw new PebbleException(
null, "Incorrect %s format, must be a number".formatted(value),
lineNumber, self != null ? self.getName() : "Unknown"
);
}
}
View on GitHub (pinned to 823fada927)
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.
Example fix
{# before #}
{{ execution.startDate | dateAdd(vars.offset, "days") }}
{# vars.offset = "two" #}
{# after #}
{{ execution.startDate | dateAdd(2, "days") }} Defensive patterns
Strategy: validation
Validate before calling
{# Ensure amount is a valid integer string or number before dateAdd #}
{% set amt = vars.offset ?? 0 %}
{% if amt is numeric %}
{{ date | dateAdd(amt, "days") }}
{% else %}
{{ date }}
{% endif %} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Incorrect %s format, must be a number
- Cannot concat {} with {}
- Could not perform greater than or equals comparison
- Could not perform greater than comparison
- Could not perform less than or equals comparison
AI-assisted analysis of kestra-io/kestra@823fada927 (2026-08-14).
Data as JSON: /api/errors/b864662ed509c714.
Report an issue: GitHub.