wavetermdev/waveterm · error
error expanding home dir: %w
Error message
error expanding home dir: %w
What it means
resolveFileQuery expands '~' in the caller-provided cwd via wavebase.ExpandHomeDir; if that expansion fails (typically HOME unset/unresolvable), the underlying error is wrapped with this message. It surfaces environment problems before any path resolution proceeds.
Source
Thrown at pkg/suggestion/suggestion.go:72
//
// Our approach is to use the presence of a trailing slash to decide whether
// to treat the query as a directory listing (searchTerm is empty) or a search
// filter. (This means that a query of exactly "." or ".." is treated as a
// search filter, so that files with a dot in their name––including ".."––will
// be returned.)
//
// In addition, if there is a slash anywhere in the query (but not at the end),
// we treat everything before the last slash as a relative directory to search
// in, and the portion after the last slash as the search term.
func resolveFileQuery(cwd string, query string) (string, string, string, error) {
// If no current working directory, default to "~".
if cwd == "" {
cwd = "~"
}
var err error
cwd, err = wavebase.ExpandHomeDir(cwd)
if err != nil {
return "", "", "", fmt.Errorf("error expanding home dir: %w", err)
}
if query == "" {
return cwd, "", "", nil
}
// Expand home if needed.
tildeSlash := "~" + PathSepStr
if query == "~" || strings.HasPrefix(query, tildeSlash) {
ogQuery := query
query, err = wavebase.ExpandHomeDir(query)
if err != nil {
return "", "", "", fmt.Errorf("error expanding query home dir: %w", err)
}
if ogQuery == "~" || ogQuery == tildeSlash {
return query, tildeSlash, "", nil
}
}
// Handle absolute queries.
if filepath.IsAbs(query) {View on GitHub (pinned to a4447c1563)
Solutions
- Ensure the HOME environment variable is set correctly for the wave process
- Pass an explicit absolute cwd in FetchSuggestionsData.FileCwd instead of relying on '~'
- Inspect the wrapped ExpandHomeDir error for the root cause (which os/user call failed)
Example fix
// before
data := wshrpc.FetchSuggestionsData{SuggestionType: "file", FileCwd: "~"}
// after
if os.Getenv("HOME") == "" {
os.Setenv("HOME", "/home/user")
}
data := wshrpc.FetchSuggestionsData{SuggestionType: "file", FileCwd: "/home/user/work"} Defensive patterns
Strategy: validation
Validate before calling
if os.Getenv("HOME") == "" {
return errors.New("HOME is not set; tilde cwd cannot be expanded")
}
if _, err := wavebase.ExpandHomeDir("~"); err != nil {
return fmt.Errorf("home expansion unavailable: %w", err)
} Type guard
func homeExpandable() bool { _, err := wavebase.ExpandHomeDir("~"); return err == nil } Try / catch
cwd, err := wavebase.ExpandHomeDir(data.FileCwd)
if err != nil {
home, hErr := os.UserHomeDir()
if hErr != nil { return err }
cwd = home
} Prevention
- Set HOME explicitly in service/container environments running wave
- Prefer absolute paths in FileCwd over '~' when the environment is uncertain
- Wrap calls so the inner ExpandHomeDir error is visible in logs
When it happens
Trigger: Calling FetchSuggestions with SuggestionType "file" and a FileCwd requiring expansion while the process HOME environment variable is empty or invalid.
Common situations: Server/daemon contexts running without a HOME env var, containerized deployments missing the user environment, corrupted passwd entries for the current user.
Related errors
- error expanding query home dir: %w
- setting auth key: %v
- electron executable path not set
- failed to build secret environment (ERR-SECRET): %w
- env string too large (max %d bytes)
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/210c10189d937609.
Report an issue: GitHub.