{"record":{"id":"60b4816f14e26b71","repo":"OrchardCMS/OrchardCore","slug":"the-variable-0-was-used-in-the-recipe-but-not-defined-make","errorCode":null,"errorMessage":"The variable '{0}' was used in the recipe but not defined. Make sure you add the '{0}' variable in the '{1}' section of the recipe.","messagePattern":"The variable '(.+?)' was used in the recipe but not defined\\. Make sure you add the '(.+?)' variable in the '(.+?)' section of the recipe\\.","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Recipes.Core/VariablesMethodProvider.cs","lineNumber":46,"sourceCode":"\n    public IEnumerable<GlobalMethod> GetMethods()\n    {\n        yield return _globalMethod;\n    }\n\n    private static async Task<object> GetVariableValueAsync(\n        IServiceProvider serviceProvider,\n        JsonObject variables,\n        List<IGlobalMethodProvider> scopedMethodProviders,\n        string name)\n    {\n        var variable = variables[name];\n\n        if (variable == null)\n        {\n            var S = serviceProvider.GetService<IStringLocalizer<VariablesMethodProvider>>();\n\n            throw new ValidationException(S[\"The variable '{0}' was used in the recipe but not defined. Make sure you add the '{0}' variable in the '{1}' section of the recipe.\", name, GlobalMethodName]);\n        }\n\n        var value = variable.Value<string>();\n\n        // Replace variable value while the result returns another script.\n        while (value.StartsWith('[') && value.EndsWith(']'))\n        {\n            value = value.Trim('[', ']');\n            value = (await ScriptingManager.EvaluateAsync(value, null, null, scopedMethodProviders) ?? \"\").ToString();\n            variables[name] = value;\n        }\n\n        return value;\n    }\n}\n","sourceCodeStart":28,"sourceCodeEnd":62,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Recipes.Core/VariablesMethodProvider.cs#L28-L62","documentation":"VariablesMethodProvider.GetVariableValueAsync resolves a recipe variable referenced by the [[VariableName]] syntax. If the named variable does not exist in the recipe's 'variables' section, it throws a ValidationException telling the author to define the variable. This fails fast during recipe execution rather than silently injecting null.","triggerScenarios":"A recipe step references a variable (e.g., [[MyVar]] in a script or parameter) that is not declared in the recipe's \"variables\" section, so VariablesMethodProvider looks it up in the variables dictionary and finds null.","commonSituations":"Typo in a [[VariableName]] reference vs. its declaration; a variable deleted from the 'variables' section while steps still reference it; copying steps from another recipe without copying the variables; case-sensitivity mismatch between reference and declaration.","solutions":["Add the missing variable to the recipe's \"variables\" section: \"variables\": { \"MyVar\": \"value\" }.","Fix the reference typo in the step so it matches a declared variable name exactly (case included).","If the value should come from user input at setup, declare it in the recipe parameters/setup settings instead of referencing an undeclared name.","Search the recipe file for all [[...]] references and reconcile them against declared variables."],"exampleFix":"// before (step references [[SiteName]] but variables section lacks it)\n{\n  \"variables\": { },\n  \"steps\": [\n    { \"type\": \"settings\", \"values\": { \"SiteName\": \"[[SiteName]]\" } }\n  ]\n}\n\n// after\n{\n  \"variables\": { \"SiteName\": \"My Site\" },\n  \"steps\": [\n    { \"type\": \"settings\", \"values\": { \"SiteName\": \"[[SiteName]]\" } }\n  ]\n}","handlingStrategy":"validation","validationCode":"var json = JsonNode.Parse(File.ReadAllText(recipePath));\nvar variables = json?[\"variables\"]?.AsObject();\nforeach (var reference in System.Text.RegularExpressions.Regex.Matches(\n             json!.ToJsonString(), \"\\[\\[(\\w+)\\]\\]\"))\n{\n    var name = reference.Groups[1].Value;\n    if (variables?[name] == null)\n        throw new Exception($\"Recipe references undefined variable '{name}'\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    await recipeExecutor.ExecuteAsync(executionId, descriptor, environment, logger);\n}\ncatch (ValidationException ex)\n{\n    logger.LogError(ex, \"Recipe references an undefined variable: {Message}\", ex.Message);\n}","preventionTips":["Declare every variable referenced with [[Name]] in the recipe's \"variables\" section.","Match variable names exactly (case-sensitive) between declarations and references.","When copying steps between recipes, copy their variable declarations too.","Grep the recipe for [[...]] patterns and reconcile against the variables section before deploying."],"tags":["recipes","variables","validation","configuration"],"backgroundTag":"missing-config-value","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}