{"record":{"id":"7151e1232d8b9873","repo":"kestra-io/kestra","slug":"e-getmessage","errorCode":null,"errorMessage":"{e.getMessage()}","messagePattern":"\\{e\\.getMessage\\(\\)\\}","errorType":"exception","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/KvFunction.java","lineNumber":70,"sourceCode":"\n        boolean errorOnMissing = Optional.ofNullable((Boolean) args.get(ERROR_ON_MISSING_ARG)).orElse(true);\n\n        Map<String, String> flow = (Map<String, String>) context.getVariable(\"flow\");\n        String flowNamespace = flow.get(NAMESPACE_ARG);\n        String flowTenantId = flow.get(\"tenantId\");\n\n        Optional<KVValue> value;\n        try {\n            if (namespace == null) {\n                namespace = flowNamespace;\n                value = getValueWithInheritance(flowNamespace, key, flowTenantId);\n            } else {\n                // we didn't check allowedNamespace here as it's checked in the kvStoreService itself\n                value = kvStoreService.get().get(flowTenantId, namespace, flowNamespace).getValue(key);\n            }\n        } catch (ResourceExpiredException e) {\n            if (errorOnMissing) {\n                throw new PebbleException(e, e.getMessage(), lineNumber, self.getName());\n            }\n            value = Optional.empty();\n        } catch (Exception e) {\n            throw new PebbleException(e, e.getMessage(), lineNumber, self.getName());\n        }\n\n        if (value.isEmpty() && errorOnMissing) {\n            throw new PebbleException(null, \"The key '\" + key + \"' does not exist in the namespace '\" + namespace + \"'.\", lineNumber, self.getName());\n        }\n\n        return value.map(KVValue::value).orElse(null);\n    }\n\n    private Optional<KVValue> getValueWithInheritance(String flowNamespace, String key, String tenantId)\n        throws IOException, ResourceExpiredException {\n        Optional<KVValue> value = Optional.empty();\n        String inheritedNamespace = flowNamespace;\n        while (value.isEmpty()) {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/KvFunction.java#L52-L88","documentation":"The kv(key, namespace, errorOnMissing) Pebble function retrieves a value from the Kestra KV store. If the stored key has expired (ResourceExpiredException) AND errorOnMissing is true (the default), the exception message is re-thrown as a PebbleException. When errorOnMissing is false, expired keys silently return null.","triggerScenarios":"Calling {{ kv('myKey') }} or {{ kv('myKey', errorOnMissing=true) }} for a key that was set with a TTL that has elapsed. The key exists in the store metadata but its value has passed the expiration timestamp.","commonSituations":"A key was written with a short TTL for caching, and the flow references it after expiry. A developer expects the key to persist indefinitely but it was created with an expiration date.","solutions":["Set errorOnMissing=false to treat expired keys the same as missing keys: {{ kv('myKey', errorOnMissing=false) }}.","Rewrite the key with a new value and TTL before accessing it, or remove the TTL entirely.","Check the KV store UI or API to inspect the key's expiration date."],"exampleFix":"# before\nvalue: \"{{ kv('myKey') }}\"\n# after\nvalue: \"{{ kv('myKey', errorOnMissing=false) }}\"","handlingStrategy":"fallback","validationCode":"# Set errorOnMissing=false to handle expired/missing keys gracefully:\n{{ kv('myKey', errorOnMissing=false) }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set errorOnMissing=false whenever a missing or expired key is an acceptable runtime condition.","Track TTLs on KV keys and refresh them before expiry.","Document which keys have expiration dates so flow authors can plan accordingly."],"tags":["pebble-function","kv-store","resource-expired"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}