kestra-io/kestra · error · PebbleException

The 'isDayWeekInMonth()' function received an invalid 'posit

Error message

The 'isDayWeekInMonth()' function received an invalid 'position' value: '{positionArg}'. Expected one of: FIRST, SECOND, THIRD, FOURTH, LAST.

What it means

The position argument must be one of FIRST, SECOND, THIRD, FOURTH, LAST (case-insensitive). The switch statement fell through to its default branch.

Source

Thrown at core/src/main/java/io/kestra/core/runners/pebble/functions/IsDayWeekInMonthFunction.java:74

        DayOfWeek dayOfWeek;
        try {
            dayOfWeek = DayOfWeek.valueOf(dayOfWeekArg.toString().toUpperCase());
        } catch (IllegalArgumentException e) {
            throw new PebbleException(
                e,
                "The 'isDayWeekInMonth()' function received an invalid 'dayOfWeek' value: '" + dayOfWeekArg
                    + "'. Expected one of: MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY.",
                lineNumber, self.getName()
            );
        }

        LocalDate computed = switch (positionArg.toString().toUpperCase()) {
            case "FIRST" -> localDate.with(TemporalAdjusters.firstInMonth(dayOfWeek));
            case "SECOND" -> localDate.with(TemporalAdjusters.firstInMonth(dayOfWeek)).plusWeeks(1);
            case "THIRD" -> localDate.with(TemporalAdjusters.firstInMonth(dayOfWeek)).plusWeeks(2);
            case "FOURTH" -> localDate.with(TemporalAdjusters.firstInMonth(dayOfWeek)).plusWeeks(3);
            case "LAST" -> localDate.with(TemporalAdjusters.lastInMonth(dayOfWeek));
            default -> throw new PebbleException(
                null, "The 'isDayWeekInMonth()' function received an invalid 'position' value: '" + positionArg + "'. Expected one of: FIRST, SECOND, THIRD, FOURTH, LAST.", lineNumber,
                self.getName()
            );
        };

        return computed.isEqual(localDate);
    }

    @Override
    public List<String> getArgumentNames() {
        return List.of("date", "dayOfWeek", "position");
    }

    @Override
    // HashMap is required here because Map.of() does not allow null values,
    // and null defaults indicate arguments with no meaningful autocompletion default.
    public Map<String, String> getArgumentDefaults() {
        HashMap<String, String> defaults = new HashMap<>();

View on GitHub (pinned to 823fada927)

Solutions

  1. Use exactly FIRST, SECOND, THIRD, FOURTH, or LAST (any case; it is upper-cased internally).

Example fix

// before
{{ isDayWeekInMonth(date='2024-01-15', dayOfWeek='MONDAY', position='1ST') }}
// after
{{ isDayWeekInMonth(date='2024-01-15', dayOfWeek='MONDAY', position='FIRST') }}
Defensive patterns

Strategy: validation

Validate before calling

{% set p = position|upper %}{% if p in ['FIRST','SECOND','THIRD','FOURTH','LAST'] %}{{ isDayWeekInMonth(date=myDate, dayOfWeek='MONDAY', position=p) }}{% endif %}

Type guard

{% macro is_valid_position(p) %}{{ p|upper in ['FIRST','SECOND','THIRD','FOURTH','LAST'] }}{% endmacro %}

Prevention

When it happens

Trigger: Passing position='1ST', '1', 'LASTDAY', 'THIRDLY', or a typo such as 'FORTH'.

Common situations: Using ordinals/numbers or misspellings instead of the exact keyword.

Related errors


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