{"record":{"id":"6656d3de39cb32f7","repo":"kestra-io/kestra","slug":"the-monthofyear-function-expects-a-date-argu","errorCode":null,"errorMessage":"The 'monthOfYear()' function expects a 'date' argument.","messagePattern":"The 'monthOfYear\\(\\)' function expects a 'date' argument\\.","errorType":"exception","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/MonthOfYearFunction.java","lineNumber":31,"sourceCode":"import io.pebbletemplates.pebble.template.PebbleTemplate;\n\n/**\n * Pebble function that returns the month of the year (1–12) of the given date.\n *\n * <p>\n * Usage: {@code {{ monthOfYear(date) }}}\n *\n * @param date any valid ISO 8601 date or datetime string\n */\npublic class MonthOfYearFunction implements KestraFunction {\n    public static final String NAME = \"monthOfYear\";\n\n    @Override\n    public Object execute(Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) {\n        Object dateArg = args.get(\"date\");\n\n        if (dateArg == null) {\n            throw new PebbleException(null, \"The 'monthOfYear()' function expects a 'date' argument.\", lineNumber, self.getName());\n        }\n\n        LocalDate localDate;\n        try {\n            localDate = DateUtils.parseLocalDate(dateArg.toString());\n        } catch (InternalException e) {\n            throw new PebbleException(e, \"The 'monthOfYear()' function could not parse 'date': \" + e.getMessage(), lineNumber, self.getName());\n        }\n\n        return localDate.getMonthValue();\n    }\n\n    @Override\n    public List<String> getArgumentNames() {\n        return List.of(\"date\");\n    }\n\n    @Override","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/MonthOfYearFunction.java#L13-L49","documentation":"The monthOfYear(date) Pebble function requires a 'date' argument. If the args map does not contain 'date' or its value is null, the function throws before any parsing occurs. This is a contract violation indicating the function was called without its required input.","triggerScenarios":"Calling {{ monthOfYear() }} with no arguments. Passing a variable that resolves to null. Using a named parameter that does not match 'date'.","commonSituations":"The flow author omits the date argument expecting a default (there is none). An upstream variable used as the date is null because the producing task has not run or produced no output.","solutions":["Supply a non-null date argument: {{ monthOfYear('2024-06-15') }} or {{ monthOfYear(myDateVar) }} where myDateVar is guaranteed non-null.","Guard against null: {% if myDateVar is not null %}{{ monthOfYear(myDateVar) }}{% endif %}."],"exampleFix":"# before\nvalue: \"{{ monthOfYear() }}\"\n# after\nvalue: \"{{ monthOfYear('2024-06-15') }}\"","handlingStrategy":"validation","validationCode":"# Guard against null before calling monthOfYear:\n{% if myDateVar is not null %}\n  {{ monthOfYear(myDateVar) }}\n{% else %}\n  {{ throw('monthOfYear requires a non-null date') }}\n{% endif %}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a non-null date argument.","Use 'is not null' guards for variables that may be absent.","Verify upstream tasks produce the expected date output."],"tags":["pebble-function","missing-argument","monthofyear"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}