wavetermdev/waveterm · error
error expanding query home dir
Error message
error expanding query home dir: %w
What it means
When the query itself starts with '~' or '~/', resolveFileQuery expands it with ExpandHomeDir and wraps any failure with this message. It distinguishes the failing query path from the earlier cwd expansion error at line 72.
Solutions
- Set/fix the HOME environment variable so tilde expansion works
- Send a fully expanded absolute path in Query instead of a tilde path
- Check the wrapped error: if it is a user-lookup failure, the username in the tilde path is wrong
Example fix
// before
query := "~/projects"
resp, err := FetchSuggestions(ctx, wshrpc.FetchSuggestionsData{SuggestionType: "file", Query: query})
// after
home, _ := os.UserHomeDir()
resp, err := FetchSuggestions(ctx, wshrpc.FetchSuggestionsData{SuggestionType: "file", Query: filepath.Join(home, "projects")}) Defensive patterns
Strategy: validation
Validate before calling
if strings.HasPrefix(query, "~") && os.Getenv("HOME") == "" {
return errors.New("query uses ~ but HOME is not set")
} Type guard
func isTildeQuery(q string) bool { return q == "~" || strings.HasPrefix(q, "~/") } Try / catch
expanded, err := wavebase.ExpandHomeDir(query)
if err != nil {
log.Printf("tilde expansion failed for %q: %v", query, err)
return fallbackSuggestions
} Prevention
- Expand tilde queries client-side when HOME is known there
- Avoid '~user' style paths unless the target user exists
- Keep HOME consistent between client and server processes
When it happens
Trigger: FetchSuggestions with SuggestionType "file" and a Query like "~/docs" while ExpandHomeDir fails (HOME unset, user lookup error).
Common situations: Headless environments without HOME, remote connections where the user's home cannot be resolved, malformed queries combining '~' with a nonexistent user (e.g. '~baduser/').
Related errors
- error expanding home dir
- electron executable path not set
- env string too large
- failed to build secret environment (ERR-SECRET)
- failed to resolve to absolute path
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/30e24db7b75ec395.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/suggestion/suggestion.go:83
// 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) {
if filepath.Dir(query) == query {
return query, query, "", nil
}
if strings.HasSuffix(query, PathSepStr) {
// Remove trailing slash for canonical directory path.
baseDir := strings.TrimRight(query, PathSepStr)
// But keep the trailing slash in the queryPrefix for display.
queryPrefix := query
return baseDir, queryPrefix, "", nil
}
// Otherwise, e.g. "/var/f"View on GitHub (pinned to a4447c1563)