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

  1. Pass a bare integer or a numeric string without decimals: '{{ mydate | dateAdd(2, "days") }}'.
  2. Strip non-numeric characters from the variable before passing it: parse or sanitize the upstream value.
  3. 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

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


AI-assisted analysis of kestra-io/kestra@823fada927 (2026-08-14). Data as JSON: /api/errors/b864662ed509c714. Report an issue: GitHub.