Skip to content

fix(data): handle os.UserHomeDir error in store initialization #79

@jongio

Description

@jongio

Summary

In internal/data/store.go line 102, the error returned by os.UserHomeDir() is silently discarded:

go homeDir, _ := os.UserHomeDir() return &Store{db: db, hasHostType: hasHostType, hasFTS5: hasFTS5, tempDir: os.TempDir(), homeDir: homeDir}, nil

If os.UserHomeDir() fails, homeDir is an empty string, which silently breaks any downstream logic that depends on the home directory path (e.g., path resolution, session-state directory lookups).

Why This Matters

  • Silent data corruption: An empty homeDir propagates through the Store and any method that builds paths relative to the home directory.
  • Hard-to-debug failures: Downstream errors will point to missing files or wrong paths with no indication that the root cause is a failed home directory lookup.
  • Platform edge cases: On CI runners, containers, or non-standard environments, HOME may not be set, making this a real failure mode.

Suggested Fix

Handle the error explicitly — either fail fast or log a warning:

go homeDir, err := os.UserHomeDir() if err != nil { return nil, fmt.Errorf("resolving home directory: %w", err) }

If graceful degradation is preferred, at minimum log the failure so it is diagnosable:

go homeDir, err := os.UserHomeDir() if err != nil { slog.Warn("could not determine home directory", "error", err) }

Smell Categories

  • Modern → Error Swallowing (ignored error return value on a fallible OS call)

Metadata

Metadata

Assignees

No one assigned

    Labels

    automatedCreated by automationsmellsCode smell detection

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions