{"record":{"id":"112e4a8dae539516","repo":"GoogleContainerTools/skaffold","slug":"retrieving-home-directory-w-112e4a","errorCode":null,"errorMessage":"retrieving home directory: %w","messagePattern":"retrieving home directory: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/skaffold/instrumentation/export.go","lineNumber":61,"sourceCode":"\tsemconv \"go.opentelemetry.io/otel/semconv/v1.17.0\"\n\t\"go.opentelemetry.io/otel/trace\"\n\t\"google.golang.org/api/option\"\n\n\t\"github.com/GoogleContainerTools/skaffold/v2/fs\"\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/constants\"\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/output/log\"\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/user\"\n\t\"github.com/GoogleContainerTools/skaffold/v2/proto/v1\"\n)\n\nfunc ExportMetrics(exitCode int) error {\n\tif !ShouldExportMetrics || meter.Command == \"\" {\n\t\tlog.Entry(context.TODO()).Debug(\"exporting metrics disabled\")\n\t\treturn nil\n\t}\n\thome, err := homedir.Dir()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"retrieving home directory: %w\", err)\n\t}\n\tmeter.ExitCode = exitCode\n\tmeter.Duration = time.Since(meter.StartTime)\n\treturn exportMetrics(context.Background(),\n\t\tfilepath.Join(home, constants.DefaultSkaffoldDir, constants.DefaultMetricFile),\n\t\tmeter)\n}\n\nfunc exportMetrics(ctx context.Context, filename string, meter skaffoldMeter) error {\n\tlog.Entry(ctx).Debug(\"exporting metrics\")\n\texp, err := initExporter()\n\tif exp == nil {\n\t\treturn err\n\t}\n\tres := resource.NewWithAttributes(\n\t\tsemconv.SchemaURL,\n\t\tsemconv.ServiceName(\"skaffold\"),\n\t\tsemconv.ServiceVersion(meter.Version),","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/instrumentation/export.go#L43-L79","documentation":"ExportMetrics (invoked at shutdown via ShutdownAndFlush) needs the user's home directory to locate the metrics file under ~/.skaffold. If homedir.Dir() fails (no HOME set, user lookup fails), the error \"retrieving home directory: %w\" is returned. Metrics export is skipped and the wrapped OS/user-lookup error is surfaced.","triggerScenarios":"Any skaffold command exit with metrics enabled (ShouldExportMetrics and meter.Command set) while the process has no resolvable home directory.","commonSituations":"Running skaffold in a container/service account with HOME unset, running under systemd or schedulers with a minimal environment, or a deleted home directory.","solutions":["Set the HOME environment variable: `export HOME=/home/<user>` before running skaffold.","Disable metrics export with `skaffold config set --global collect-metrics false` to skip the code path.","Ensure the configured user exists in /etc/passwd when running as a service."],"exampleFix":"// before\nskaffold run  # HOME unset in container\n// after\nENV HOME=/root\nRUN skaffold config set --global collect-metrics false","handlingStrategy":"try-catch","validationCode":"if os.Getenv(\"HOME\") == \"\" {\n    log.Println(\"HOME is unset; metrics export will fail\")\n}","typeGuard":null,"tryCatchPattern":"if err := skaffoldCmd.Run(); err != nil {\n    if strings.Contains(err.Error(), \"retrieving home directory\") {\n        // non-fatal: set HOME and retry or ignore telemetry failure\n    }\n}","preventionTips":["Always set HOME in containers and service environments","Disable metrics collection where home lookup is unavailable","Ensure the runtime user has a valid passwd entry"],"tags":["environment","home-directory","telemetry"],"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"}