{"record":{"id":"c15a66adb797e85e","repo":"kestra-io/kestra","slug":"the-errorlogs-function-can-only-be-used-in-the-w","errorCode":null,"errorMessage":"The 'errorLogs' function can only be used in the Worker as it access logs from the database.","messagePattern":"The 'errorLogs' function can only be used in the Worker as it access logs from the database\\.","errorType":"validation","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/ErrorLogsFunction.java","lineNumber":45,"sourceCode":"\n    @Inject\n    private Provider<PebbleUtils> pebbleUtils;\n\n    @Override\n    public List<String> getArgumentNames() {\n        return Collections.emptyList();\n    }\n\n    @Override\n    public Map<String, String> getArgumentDefaults() {\n        return Map.of();\n    }\n\n    @Override\n    @SuppressWarnings(\"unchecked\")\n    public Object execute(Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) {\n        if (!pebbleUtils.get().calledOnWorker()) {\n            throw new PebbleException(null, \"The 'errorLogs' function can only be used in the Worker as it access logs from the database.\", lineNumber, self.getName());\n        }\n\n        Map<String, String> flow = (Map<String, String>) context.getVariable(\"flow\");\n        Map<String, String> execution = (Map<String, String>) context.getVariable(\"execution\");\n\n        RetryUtils.Instance<List<LogEntry>, Throwable> retry = RetryUtils.of(\n            Exponential.builder()\n                .delayFactor(2.0)\n                .interval(Duration.ofMillis(100))\n                .maxInterval(Duration.ofSeconds(1))\n                .maxAttempts(-1)\n                .maxDuration(Duration.ofSeconds(5))\n                .build()\n        );\n\n        try {\n            return retry.run(logs -> ListUtils.isEmpty(logs), () -> executionLogMetaStore.get().errorLogs(flow.get(\"tenantId\"), execution.get(\"id\")));\n        } catch (RetryUtils.RetryFailed e) {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/ErrorLogsFunction.java#L27-L63","documentation":"Thrown by the Pebble 'errorLogs' function when pebbleUtils.get().calledOnWorker() returns false. The function reads logs from the database via executionLogMetaStore, an accessor that is only valid inside a Worker task execution. Calling it elsewhere (e.g. in flow-level rendering, triggers, or the webserver) is unsupported because the log store and the flow/execution context variables it needs are not available there.","triggerScenarios":"Using errorLogs() in a flow-level property (e.g. on a trigger, a schedule, or top-level description), in a subflow mapping evaluated outside the worker, or in any template rendered before/at dispatch rather than during task execution on a worker.","commonSituations":"Putting errorLogs() in an SLA/alert field, a trigger configuration, or an error flow's inputs; rendering a summary string at the flow level instead of inside a task that runs on the worker.","solutions":["Move the errorLogs() call into a property that is evaluated by a worker task (e.g. a Log, Shell, or io.kestra task's input), not a flow-level or trigger-level field.","If you need the logs in a different context, capture them inside the worker task and pass the result downstream via outputs/outputs variables.","Confirm the task type actually executes on the worker (not an executor/scheduler-only component)."],"exampleFix":"# before - errorLogs() at trigger level is rejected\ntasks:\n  - id: warn\n    type: io.kestra.plugin.core.log.Log\n    message: \"{{ errorLogs() }}\"\n# errorLogs() is fine here because Log runs on the worker; ensure you are NOT calling it in triggers/flow-level fields","handlingStrategy":"validation","validationCode":"# errorLogs() is valid only in worker tasks. Before adding it, confirm the field is evaluated by a worker-executed task.\n# Static guidance: only call errorLogs() inside a task input (e.g. io.kestra.plugin.core.log.Log), never in triggers or flow-level fields.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only call errorLogs() inside tasks that run on the worker.","Never place it in trigger, schedule, or flow-level properties.","Capture logs in a worker task and pass results downstream via outputs if needed elsewhere.","Review where a template field is rendered before using context-dependent functions."],"tags":["pebble","errorlogs","worker","runtime-context","validation"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}