{"record":{"id":"b8c1830ebe275f21","repo":"nats-io/nats-server","slug":"nats-failed-to-get-home-dir-require-homedrive","errorCode":null,"errorMessage":"nats: failed to get home dir, require %HOMEDRIVE% and %HOMEPATH% or %USERPROFILE%","messagePattern":"nats: failed to get home dir, require %HOMEDRIVE% and %HOMEPATH% or %USERPROFILE%","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/opts.go","lineNumber":6598,"sourceCode":"// 1. Try to open a file with path \"pidStr\" (absolute or relative).\n// 2. If such a file exists and can be read, return its contents.\n// 3. Otherwise, return the original \"pidStr\" string.\nfunc maybeReadPidFile(pidStr string) string {\n\tif b, err := os.ReadFile(pidStr); err == nil {\n\t\treturn string(b)\n\t}\n\treturn pidStr\n}\n\nfunc homeDir() (string, error) {\n\tif runtime.GOOS == \"windows\" {\n\t\thomeDrive, homePath := os.Getenv(\"HOMEDRIVE\"), os.Getenv(\"HOMEPATH\")\n\t\tuserProfile := os.Getenv(\"USERPROFILE\")\n\n\t\thome := filepath.Join(homeDrive, homePath)\n\t\tif homeDrive == _EMPTY_ || homePath == _EMPTY_ {\n\t\t\tif userProfile == _EMPTY_ {\n\t\t\t\treturn _EMPTY_, errors.New(\"nats: failed to get home dir, require %HOMEDRIVE% and %HOMEPATH% or %USERPROFILE%\")\n\t\t\t}\n\t\t\thome = userProfile\n\t\t}\n\n\t\treturn home, nil\n\t}\n\n\thome := os.Getenv(\"HOME\")\n\tif home == _EMPTY_ {\n\t\treturn _EMPTY_, errors.New(\"failed to get home dir, require $HOME\")\n\t}\n\treturn home, nil\n}\n\nfunc expandPath(p string) (string, error) {\n\tp = os.ExpandEnv(p)\n\n\tif !strings.HasPrefix(p, \"~\") {","sourceCodeStart":6580,"sourceCodeEnd":6616,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/opts.go#L6580-L6616","documentation":"homeDir() on Windows: neither HOMEDRIVE+HOMEPATH nor USERPROFILE environment variables are set, so the user home directory — used to resolve relative config and pid paths — cannot be determined. The missing Windows environment variables are the input at fault.","triggerScenarios":"Thrown at server/opts.go:6598 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set HOMEDRIVE/HOMEPATH or USERPROFILE in the service environment","Pass absolute paths for config and pid files so home resolution is unnecessary","Run the server from a properly configured user profile"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}