{"record":{"id":"6cf04fcb93b6cf39","repo":"docker/cli","slug":"error-while-interpolating-s-w","errorCode":null,"errorMessage":"error while interpolating %s: %w","messagePattern":"error while interpolating (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/compose/interpolation/interpolation.go","lineNumber":111,"sourceCode":"\t\t\tout[i] = interpolatedElem\n\t\t}\n\t\treturn out, nil\n\n\tdefault:\n\t\treturn value, nil\n\t}\n}\n\nfunc newPathError(path Path, err error) error {\n\tswitch err := err.(type) {\n\tcase nil:\n\t\treturn nil\n\tcase *template.InvalidTemplateError:\n\t\treturn fmt.Errorf(\n\t\t\t\"invalid interpolation format for %s: %#v; you may need to escape any $ with another $\",\n\t\t\tpath, err.Template)\n\tdefault:\n\t\treturn fmt.Errorf(\"error while interpolating %s: %w\", path, err)\n\t}\n}\n\nconst pathSeparator = \".\"\n\n// PathMatchAll is a token used as part of a Path to match any key at that level\n// in the nested structure\nconst PathMatchAll = \"*\"\n\n// PathMatchList is a token used as part of a Path to match items in a list\nconst PathMatchList = \"[]\"\n\n// Path is a dotted path of keys to a value in a nested mapping structure. A *\n// section in a path will match any key in the mapping structure.\ntype Path string\n\n// NewPath returns a new Path\nfunc NewPath(items ...string) Path {","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/compose/interpolation/interpolation.go#L93-L129","documentation":"Returned by newPathError as the catch-all for interpolation errors that are not *template.InvalidTemplateError (interpolation.go:110-112). The most common inner cause is a required variable referenced with ${VAR} (no default) that is not present in the lookup map, which the template engine reports as a 'required variable' error.","triggerScenarios":"A compose value references ${VAR} (or ${VAR?...}) and VAR is not set in the environment/lookup, and the template engine treats it as required. Also any non-InvalidTemplateError returned by the Substitute function lands here.","commonSituations":"Forgetting to export an env var the compose file expects; running on a host/CI without the .env file loaded; referencing a secret/variable that is intentionally required to fail fast.","solutions":["Set the missing variable in the environment or a .env file.","Provide a default with ${VAR:-default} if the variable is optional.","Use ${VAR?error message} intentionally only where you want a clear failure."],"exampleFix":"# before\nservices:\n  app:\n    image: app:${TAG}\n# after (give a default)\nservices:\n  app:\n    image: app:${TAG:-latest}","handlingStrategy":"try-catch","validationCode":"// Provide defaults for optional vars to avoid 'required variable' errors.\n// In compose: image: app:${TAG:-latest}\n// Programmatically, ensure all required vars are present:\nfunc ensureEnv(vars ...string) error {\n    for _, v := range vars {\n        if _, ok := os.LookupEnv(v); !ok {\n            return fmt.Errorf(\"required env var %s is not set\", v)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"loaded, err := loader.Load(details)\nif err != nil {\n    if strings.Contains(err.Error(), \"interpolating\") {\n        // likely a missing required variable; prompt for / set the env var and retry\n    }\n    return err\n}","preventionTips":["Provide defaults (${VAR:-default}) for optional variables.","Load a .env file or export required vars before running compose.","Use ${VAR?reason} only where you want an explicit, named failure."],"tags":["compose","interpolation","env","required-variable"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}