{"record":{"id":"0a082dc99e99e1b8","repo":"dagger/dagger","slug":"key-q-is-missing-an-environment-name","errorCode":null,"errorMessage":"key %q is missing an environment name","messagePattern":"key %q is missing an environment name","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/workspace/userconfig.go","lineNumber":237,"sourceCode":"\tif !ok {\n\t\treturn \"\", false\n\t}\n\tgitDir = strings.TrimSpace(gitDir)\n\treturn gitDir, gitDir != \"\"\n}\n\n// userOverlayKeyParts validates that key addresses user-overridable config and\n// returns its parsed path segments. Only module settings may be stored in a\n// user-level overlay, always applied or scoped to an environment.\nfunc userOverlayKeyParts(key string) ([]string, error) {\n\tparts, err := splitConfigPath(key)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\trest := parts\n\tif len(rest) > 0 && rest[0] == \"env\" {\n\t\tif len(rest) < 2 {\n\t\t\treturn nil, fmt.Errorf(\"key %q is missing an environment name\", key)\n\t\t}\n\t\trest = rest[2:]\n\t}\n\tif len(rest) < 4 || rest[0] != \"modules\" || rest[2] != \"settings\" {\n\t\treturn nil, fmt.Errorf(\"key %q cannot be stored in user-level config; only modules.<name>.settings.* and env.<name>.modules.<name>.settings.* are supported\", key)\n\t}\n\treturn parts, nil\n}\n\n// WriteUserConfigValue sets a config value under [workspaces.<workspaceKey>]\n// in user-level config bytes, preserving unrelated sections (e.g. [llm]) and\n// other workspace entries. The workspace key is canonicalized; when an entry\n// for an equivalent remote spelling already exists, it is updated in place\n// rather than duplicated. A non-nil values slice stores a string array\n// verbatim; otherwise rawValue is typed like repository config writes.\nfunc WriteUserConfigValue(existing []byte, workspaceKey, key, rawValue string, values []string) ([]byte, error) {\n\tparts, err := userOverlayKeyParts(key)\n\tif err != nil {","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/workspace/userconfig.go#L219-L255","documentation":"userOverlayKeyParts parses user-level config keys and supports an optional \"env.<name>.\" prefix identifying an environment. When the key starts with \"env\" but has no environment name following it (e.g. \"env.modules.foo.settings.x\"), this error is thrown because the parser cannot tell which environment the key belongs to.","triggerScenarios":"Calling WriteUserConfigValue or DeleteUserConfigValue with a key whose first segment is \"env\" followed by fewer than 2 remaining segments — e.g. \"env\", \"env.x\", or \"env.modules.foo.settings.x\" (env immediately followed by modules).","commonSituations":"Typing a config key without the environment name (\"dagger config set env.modules.x...\"); scripting that drops a segment when building keys programmatically; documentation examples copied incompletely.","solutions":["Add the environment name after \"env\": use \"env.<name>.modules.<mod>.settings.<key>\"","If you do not mean an environment, drop the \"env\" segment and use \"modules.<mod>.settings.<key>\"","Split the key on \".\" and verify segment 2 (index 1) is the environment name, not \"modules\""],"exampleFix":"// before\nWriteUserConfigValue(data, \"env.modules.foo.settings.timeout\", \"30\")\n// after\nWriteUserConfigValue(data, \"env.ci.modules.foo.settings.timeout\", \"30\")","handlingStrategy":"validation","validationCode":"segs := strings.Split(key, \".\")\nif segs[0] == \"env\" && len(segs) < 5 {\n\treturn fmt.Errorf(\"env-scoped keys need: env.<name>.modules.<mod>.settings.<key>\")\n}","typeGuard":"func isWellFormedEnvKey(key string) bool {\n\ts := strings.Split(key, \".\")\n\treturn len(s) < 2 || s[0] != \"env\" || (len(s) >= 5 && s[1] != \"\" && s[1] != \"modules\")\n}","tryCatchPattern":"_, err := workspace.WriteUserConfigValue(data, key, wsKey, val)\nif err != nil && strings.Contains(err.Error(), \"missing an environment name\") {\n\treturn fmt.Errorf(\"key %q must include the environment name after 'env'\", key)\n}","preventionTips":["Always spell env keys fully: env.<name>.modules.<mod>.settings.<key>","Build keys from a helper function, never string concatenation by hand","Unit-test key builders with env-prefixed cases"],"tags":["go","config","user-config","key-format"],"backgroundTag":"invalid-config-key","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}