GoogleContainerTools/skaffold · warning
retrieving home directory: %w
Error message
retrieving home directory: %w
What it means
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.
Source
Thrown at pkg/skaffold/instrumentation/export.go:61
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
"go.opentelemetry.io/otel/trace"
"google.golang.org/api/option"
"github.com/GoogleContainerTools/skaffold/v2/fs"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/output/log"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/user"
"github.com/GoogleContainerTools/skaffold/v2/proto/v1"
)
func ExportMetrics(exitCode int) error {
if !ShouldExportMetrics || meter.Command == "" {
log.Entry(context.TODO()).Debug("exporting metrics disabled")
return nil
}
home, err := homedir.Dir()
if err != nil {
return fmt.Errorf("retrieving home directory: %w", err)
}
meter.ExitCode = exitCode
meter.Duration = time.Since(meter.StartTime)
return exportMetrics(context.Background(),
filepath.Join(home, constants.DefaultSkaffoldDir, constants.DefaultMetricFile),
meter)
}
func exportMetrics(ctx context.Context, filename string, meter skaffoldMeter) error {
log.Entry(ctx).Debug("exporting metrics")
exp, err := initExporter()
if exp == nil {
return err
}
res := resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceName("skaffold"),
semconv.ServiceVersion(meter.Version),View on GitHub (pinned to a1189de023)
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.
Example fix
// before skaffold run # HOME unset in container // after ENV HOME=/root RUN skaffold config set --global collect-metrics false
Defensive patterns
Strategy: try-catch
Validate before calling
if os.Getenv("HOME") == "" {
log.Println("HOME is unset; metrics export will fail")
} Try / catch
if err := skaffoldCmd.Run(); err != nil {
if strings.Contains(err.Error(), "retrieving home directory") {
// non-fatal: set HOME and retry or ignore telemetry failure
}
} Prevention
- 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
When it happens
Trigger: Any skaffold command exit with metrics enabled (ShouldExportMetrics and meter.Command set) while the process has no resolvable home directory.
Common situations: Running skaffold in a container/service account with HOME unset, running under systemd or schedulers with a minimal environment, or a deleted home directory.
Related errors
- retrieving home directory: %w
- unable to lookup minikube executable. Please add it to PATH
- getting minikube executable: %w
- unable to find minikube executable. File not found %s
- retrieving home directory: %w
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/112e4a8dae539516.
Report an issue: GitHub.