{"record":{"id":"84d01ae6bc601c6d","repo":"JanDeDobbeleer/oh-my-posh","slug":"error-malformed-registry-path-s","errorCode":null,"errorMessage":"Error, malformed registry path: '%s'","messagePattern":"Error, malformed registry path: '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/runtime/terminal_windows.go","lineNumber":141,"sourceCode":"// If the path ends in \"\\\", the \"(Default)\" key in that path is retrieved.\nfunc (term *Terminal) WindowsRegistryKeyValue(input string) (*WindowsRegistryValue, error) {\n\tdefer log.Trace(time.Now(), input)\n\n\t// Format:\n\t// \"HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\EditionID\"\n\t//   1  |                  2                         |   3\n\t//\n\t// Split into:\n\t//\n\t// 1. Root key - extract the root HKEY string and turn this into a handle to get started\n\t// 2. Path - open this path\n\t// 3. Key - get this key value\n\t//\n\t// If 3 is \"\" (i.e. the path ends with \"\\\"), then get (Default) key.\n\t//\n\trootKey, regPath, found := strings.Cut(input, `\\`)\n\tif !found {\n\t\terr := fmt.Errorf(\"Error, malformed registry path: '%s'\", input)\n\t\tlog.Error(err)\n\t\treturn nil, err\n\t}\n\n\tvar regKey string\n\tif !strings.HasSuffix(regPath, `\\`) {\n\t\tregKey = path.Base(regPath)\n\t\tif len(regKey) != 0 {\n\t\t\tregPath = strings.TrimSuffix(regPath, `\\`+regKey)\n\t\t}\n\t}\n\n\tvar key registry.Key\n\tswitch rootKey {\n\tcase \"HKCR\", \"HKEY_CLASSES_ROOT\":\n\t\tkey = windows.HKEY_CLASSES_ROOT\n\tcase \"HKCC\", \"HKEY_CURRENT_CONFIG\":\n\t\tkey = windows.HKEY_CURRENT_CONFIG","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/runtime/terminal_windows.go#L123-L159","documentation":"WindowsRegistryKeyValue parses an input string of the form \"ROOT\\Path\\Key\" (or \"ROOT\\Path\\\" for the Default value). strings.Cut on the first backslash must produce both a root key and a remainder; if the input contains no backslash at all, the path is malformed and the function returns this error instead of querying the registry.","triggerScenarios":"Calling WindowsRegistryKeyValue (e.g. via a registry template property in a config) with a string lacking a backslash - like \"HKLM\" alone, an environment variable that resolved to a bare key name, or using forward slashes instead of backslashes.","commonSituations":"Config typos in a custom prompt's registry lookup; a template variable that expands to an empty or partial path; copying a registry path that uses \"/\" separators.","solutions":["Include the full path with backslashes, e.g. \"HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\EditionID\".","Check the config value that feeds the registry property - ensure any template variables expand to a full path.","Verify you use backslash (\\) as the separator, not forward slash.","If you want the Default value of a key, end the path with a trailing backslash (e.g. \"HKLM\\Software\\X\\\")."],"exampleFix":"// before (template/config)\nregistry = \"HKLM\"\n\n// after\nregistry = \"HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\EditionID\"","handlingStrategy":"validation","validationCode":"func validRegistryPath(p string) bool {\n    return strings.Contains(p, \"\\\\\") && strings.Index(p, \"\\\\\") > 0\n}\n// call only if validRegistryPath(path)","typeGuard":"func looksLikeRegistryPath(s string) bool {\n    i := strings.Index(s, \"\\\\\")\n    return i > 0\n}","tryCatchPattern":"val, err := term.WindowsRegistryKeyValue(input)\nif err != nil && strings.Contains(err.Error(), \"malformed registry path\") {\n    // fall back to a default value or hide the segment\n    return defaultRegistryValue\n}","preventionTips":["Always use backslash separators in registry paths","Include root key + at least one path component, e.g. HKCU\\Software\\Key","Verify template variables expand to full paths before render","End the path with \\ only when you want the (Default) value"],"tags":["windows","registry","config","input-validation"],"backgroundTag":"malformed-registry-path","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}