{"record":{"id":"afa083a165eb8c20","repo":"kestra-io/kestra","slug":"the-env-function-expects-an-argument-name","errorCode":null,"errorMessage":"The 'env' function expects an argument 'name'.","messagePattern":"The 'env' function expects an argument 'name'\\.","errorType":"validation","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/EnvFunction.java","lineNumber":52,"sourceCode":"        String name = getName(args, self, lineNumber);\n        Object defaultValue = args.get(DEFAULT_ARG);\n        Object envsVariable = context.getVariable(RunVariables.ENVS);\n\n        if (!(envsVariable instanceof Map<?, ?> envs)) {\n            return defaultValue;\n        }\n\n        Object value = envs.get(name);\n        if (value == null || value.toString().isEmpty()) {\n            return defaultValue;\n        }\n\n        return value;\n    }\n\n    protected String getName(Map<String, Object> args, PebbleTemplate self, int lineNumber) {\n        if (!args.containsKey(NAME_ARG)) {\n            throw new PebbleException(null, \"The 'env' function expects an argument 'name'.\", lineNumber, self.getName());\n        }\n\n        return (String) args.get(NAME_ARG);\n    }\n}\n","sourceCodeStart":34,"sourceCodeEnd":58,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/EnvFunction.java#L34-L58","documentation":"Thrown by the Pebble 'env' template function when the args map does not contain the required 'name' entry (NAME_ARG). The function reads environment variables by name; without a name there is nothing to look up, so getName() rejects the call before touching envs. A separate, earlier branch returns a default value when the variable is present but empty.","triggerScenarios":"Calling env() with no arguments, env('') (empty name bound under a different arg key), or env(default='x') with no name. Also hit if the argument is named anything other than 'name'.","commonSituations":"Typing env() instead of env('VAR_NAME'); passing a variable whose name is computed from an expression that evaluated to empty; mixing up argument order; copying a snippet that omitted the name.","solutions":["Call env with a literal or expression name: env('MY_VAR') or env(inputs.var_name).","If you want a fallback, use the default argument: env('MY_VAR', default='fallback').","Make sure any expression used as the name resolves to a non-empty string before the call."],"exampleFix":"# before\nhost: \"{{ env() }}\"\n# after\nhost: \"{{ env('DATABASE_HOST', default='localhost') }}\"","handlingStrategy":"validation","validationCode":"# Ensure the name resolves to a non-empty string before calling env().\n# {{ (varName != null and varName is not empty) ? env(varName, default='fallback') : 'fallback' }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a literal or expression name to env(): env('VAR_NAME').","Provide a 'default' argument for optional variables.","Confirm any expression feeding the name is non-empty.","Spell the argument exactly as 'name'."],"tags":["pebble","env","validation","missing-argument","environment"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}