{"record":{"id":"6c26ac04320f5b13","repo":"GoogleContainerTools/skaffold","slug":"retrieving-home-directory-w-6c26ac","errorCode":null,"errorMessage":"retrieving home directory: %w","messagePattern":"retrieving home directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/event/v2/event.go","lineNumber":386,"sourceCode":"\t\t}\n\t}\n\n\t// Write contents of temporary buffer to file\n\tif _, err = f.Write(contents.Bytes()); err != nil {\n\t\treturn fmt.Errorf(\"writing buffer contents to file: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc lastLogFile(fp string) (string, error) {\n\tif fp != \"\" {\n\t\treturn fp, nil\n\t}\n\n\t// last log location unspecified, use ~/.skaffold/last.log\n\thome, err := homedir.Dir()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"retrieving home directory: %w\", err)\n\t}\n\treturn filepath.Join(home, constants.DefaultSkaffoldDir, \"last.log\"), nil\n}\n","sourceCodeStart":368,"sourceCodeEnd":390,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/event/v2/event.go#L368-L390","documentation":"lastLogFile resolves the destination for the last log. When no explicit path is given, it defaults to ~/.skaffold/last.log by calling homedir.Dir(); failure of that call is wrapped as this error. Without a home directory the library cannot infer a default location, so SaveLastLog cannot proceed.","triggerScenarios":"Calling SaveLastLog(\"\") on a system where homedir.Dir() errors: HOME environment variable unset/empty, the OS reports no home directory for the current UID, or the underlying lookup returns an unusable path.","commonSituations":"Minimal Docker containers running as non-root without HOME set; systemd services with a sanitized environment; users without a passwd home entry; cross-platform (Windows) profile lookup failures.","solutions":["Set HOME (or USERPROFILE on Windows) to a valid writable directory before invoking skaffold.","Pass an explicit path to SaveLastLog to bypass home-directory resolution entirely.","Ensure the OS user has a valid home directory entry."],"exampleFix":"// shell\nexport HOME=/home/user   # or: docker run -e HOME=/tmp ...\n// code alternative\nerr := event.SaveLastLog(\"/tmp/skaffold-last.log\")","handlingStrategy":"validation","validationCode":"if home, err := os.UserHomeDir(); err != nil || home == \"\" {\n    return errors.New(\"no home directory available; pass an explicit SaveLastLog path\")\n}","typeGuard":null,"tryCatchPattern":"if err := event.SaveLastLog(\"\"); err != nil {\n    if strings.Contains(err.Error(), \"retrieving home directory\") {\n        return event.SaveLastLog(filepath.Join(os.TempDir(), \"last.log\"))\n    }\n    return err\n}","preventionTips":["Set HOME (or USERPROFILE) in containers, services, and cron jobs","Create OS users with valid home directories","Prefer explicit paths over the ~/.skaffold default in automation"],"tags":["environment","home-directory","configuration"],"backgroundTag":"home-directory-not-found","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}