{"record":{"id":"fc2060676c80478e","repo":"bcicen/ctop","slug":"home-not-set","errorCode":null,"errorMessage":"$HOME not set","messagePattern":"\\$HOME not set","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/file.go","lineNumber":119,"sourceCode":"\tfile, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)\n\tif err != nil {\n\t\treturn path, fmt.Errorf(\"failed to open config for writing: %s\", err)\n\t}\n\n\twriter := toml.NewEncoder(file)\n\terr = writer.Encode(exportConfig())\n\tif err != nil {\n\t\treturn path, fmt.Errorf(\"failed to write config: %s\", err)\n\t}\n\n\treturn path, nil\n}\n\n// determine config path from environment\nfunc getConfigPath() (path string, err error) {\n\thomeDir, ok := os.LookupEnv(\"HOME\")\n\tif !ok {\n\t\treturn path, fmt.Errorf(\"$HOME not set\")\n\t}\n\n\t// use xdg config home if possible\n\tif xdgSupport() {\n\t\txdgHome, ok := os.LookupEnv(\"XDG_CONFIG_HOME\")\n\t\tif !ok {\n\t\t\txdgHome = fmt.Sprintf(\"%s/.config\", homeDir)\n\t\t}\n\t\tpath = fmt.Sprintf(\"%s/ctop/config\", xdgHome)\n\t} else {\n\t\tpath = fmt.Sprintf(\"%s/.ctop\", homeDir)\n\t}\n\n\treturn path, nil\n}\n\n// test for environemnt supporting XDG spec\nfunc xdgSupport() bool {","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/bcicen/ctop/blob/59f00dd6aaebf48f3bc501e174f75f815c2619f0/config/file.go#L101-L137","documentation":"getConfigPath derives the config file location from the environment. If the HOME environment variable is not set, it cannot determine where to read/write the config and returns the '$HOME not set' error. Read and Write both depend on it.","triggerScenarios":"Calling config.Read() or config.Write() in a process whose environment lacks HOME — e.g. a daemon/systemd service, cron job, or container run without HOME.","commonSituations":"Systemd unit with a minimal Environment; Docker containers running as non-root without ENV HOME; exec environments stripped via env -i.","solutions":["Set the HOME environment variable for the process (e.g. Environment=HOME=/home/user in systemd, ENV HOME in Dockerfile)","Run the process as a user whose HOME is defined","Check the runtime environment (os.Getenv) before launching"],"exampleFix":"// before\n# docker run app  # no HOME\n// after\n# docker run -e HOME=/home/app app","handlingStrategy":"validation","validationCode":"if os.Getenv(\"HOME\") == \"\" {\n    os.Setenv(\"HOME\", \"/tmp\") // or refuse to start with a clear message\n}","typeGuard":"func homeSet() bool { _, ok := os.LookupEnv(\"HOME\"); return ok }","tryCatchPattern":"_, err := config.Read()\nif err != nil && err.Error() == \"$HOME not set\" {\n    // set HOME or use an explicit config path\n}","preventionTips":["Set HOME explicitly in systemd units, cron, and containers","Smoke-test env in CI with env -i to catch missing vars","Prefer XDG_CONFIG_HOME with a sane fallback"],"tags":["environment","config","home-dir"],"backgroundTag":"missing-env-var","analyzedSha":"59f00dd6aaebf48f3bc501e174f75f815c2619f0","analyzedAt":"2026-09-02T23:34:03.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}