{"record":{"id":"fd4add26ef01317a","repo":"nats-io/nats-server","slug":"failed-to-get-home-dir-require-home","errorCode":null,"errorMessage":"failed to get home dir, require $HOME","messagePattern":"failed to get home dir, require \\$HOME","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/opts.go","lineNumber":6608,"sourceCode":"func 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, \"~\") {\n\t\treturn p, nil\n\t}\n\n\thome, err := homeDir()\n\tif err != nil {\n\t\treturn _EMPTY_, err\n\t}\n\n\treturn filepath.Join(home, p[1:]), nil\n}","sourceCodeStart":6590,"sourceCodeEnd":6626,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/opts.go#L6590-L6626","documentation":"homeDir() on non-Windows platforms: the HOME environment variable is empty, so the home directory cannot be resolved for relative paths such as config or pid files. The unset $HOME is the input at fault.","triggerScenarios":"Thrown at server/opts.go:6608 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Export HOME in the shell or service environment","Use absolute paths for -c/-P and similar file options","For systemd units, set Environment=HOME=... in the unit file"],"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-08T10:18:20.063Z"}