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

  1. Set/fix the HOME environment variable so tilde expansion works
  2. Send a fully expanded absolute path in Query instead of a tilde path
  3. 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

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


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)