{"record":{"id":"62227d9de4e58f22","repo":"kestra-io/kestra","slug":"the-taskswithstate-function-expects-an-argument","errorCode":null,"errorMessage":"The 'tasksWithState' function expects an argument 'state'.","messagePattern":"The 'tasksWithState' function expects an argument 'state'\\.","errorType":"exception","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/TasksWithStateFunction.java","lineNumber":28,"sourceCode":"import io.pebbletemplates.pebble.template.EvaluationContextImpl;\nimport io.pebbletemplates.pebble.template.PebbleTemplate;\n\npublic class TasksWithStateFunction implements KestraFunction {\n    public static final String NAME = \"tasksWithState\";\n\n    public List<String> getArgumentNames() {\n        return List.of(\"state\");\n    }\n\n    @Override\n    public Map<String, String> getArgumentDefaults() {\n        return Map.of(\"state\", \"'FAILED'\");\n    }\n\n    @Override\n    public Object execute(Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) {\n        if (!args.containsKey(\"state\")) {\n            throw new PebbleException(null, \"The 'tasksWithState' function expects an argument 'state'.\", lineNumber, self.getName());\n        }\n        String stateToFilter = ((String) args.get(\"state\")).toUpperCase();\n\n        EvaluationContextImpl evaluationContext = (EvaluationContextImpl) context;\n\n        Map<String, Object> globalTasksMap = (Map<String, Object>) evaluationContext.getScopeChain().getGlobalScopes().stream()\n            .flatMap(scope -> scope.getKeys().stream())\n            .distinct()\n            .filter(key -> \"tasks\".equals(key)) // Filter for the \"tasks\" key specifically\n            .collect(HashMap::new, (m, k) -> m.put(k, context.getVariable(k)), HashMap::putAll)\n            .get(\"tasks\");\n\n        List<Map<String, Object>> filteredTasks = new ArrayList<>();\n\n        if (globalTasksMap != null) {\n            globalTasksMap.forEach((taskId, taskDetailsObj) ->\n            {\n                if (taskDetailsObj instanceof Map) {","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/TasksWithStateFunction.java#L10-L46","documentation":"The Pebble `tasksWithState()` function requires a single argument named `state`. The function checks `args.containsKey(\"state\")` at the top of `execute()` and throws if it is absent. This is a template-authoring error indicating the function was called without its sole parameter.","triggerScenarios":"Calling `tasksWithState()` with no arguments. Calling it with a differently-named argument. The Pebble engine only populates `args` with explicitly named arguments that are present in the call.","commonSituations":"A developer forgets the argument or uses the wrong name. The function signature changed in a version upgrade and old templates are incompatible.","solutions":["Provide the `state` argument explicitly: `tasksWithState(state='FAILED')`.","Check that the argument name is exactly `state` (case-sensitive).","Note the default value is `'FAILED'`, but the key must still be present in args."],"exampleFix":"# before\n{{ tasksWithState() }}\n# after\n{{ tasksWithState(state='FAILED') }}","handlingStrategy":"validation","validationCode":"# Pebble template: always pass the state argument explicitly\n{{ tasksWithState(state='FAILED') }}\n{{ tasksWithState(state='SUCCESS') }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always provide the named argument: tasksWithState(state='...').","Use a linter or template validator to check required Pebble function arguments."],"tags":["pebble","taskswithstate","argument-error","validation"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}