wavetermdev/waveterm · error

error resolving base dir: %w

Error message

error resolving base dir: %w

What it means

fetchFileSuggestions wraps any error from resolveFileQuery (which resolves cwd, expands tilde paths, and computes the search term) with "error resolving base dir". It is an aggregate wrapper; the root cause is inside resolveFileQuery, e.g. home-dir expansion failure (lines 72/83) or path validation.

Source

Thrown at pkg/suggestion/suggestion.go:369

func (h *scoredEntryHeap) Push(x interface{}) { *h = append(*h, x.(scoredEntry)) }
func (h *scoredEntryHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func fetchFileSuggestions(ctx context.Context, data wshrpc.FetchSuggestionsData) (*wshrpc.FetchSuggestionsResponse, error) {
	// Only support file suggestions.
	if data.SuggestionType != "file" {
		return nil, fmt.Errorf("unsupported suggestion type: %q", data.SuggestionType)
	}

	// Resolve the base directory, query prefix (for display) and search term.
	baseDir, queryPrefix, searchTerm, err := resolveFileQuery(data.FileCwd, data.Query)
	if err != nil {
		return nil, fmt.Errorf("error resolving base dir: %w", err)
	}

	// Use a cancellable context for directory listing.
	listingCtx, cancelFn := context.WithCancel(ctx)
	defer cancelFn()

	entriesCh, err := listDirectory(listingCtx, data.WidgetId, baseDir, 1000)
	if err != nil {
		return nil, fmt.Errorf("error listing directory: %w", err)
	}

	const maxEntries = MaxSuggestions // top-k entries

	// Always use a heap.
	var topHeap scoredEntryHeap
	heap.Init(&topHeap)

	var patternRunes []rune

View on GitHub (pinned to a4447c1563)

Solutions

  1. Inspect the wrapped inner error (%w chain) to find whether it is the cwd (line 72) or query (line 83) expansion failing
  2. Fix HOME environment or pass absolute FileCwd/Query values
  3. Fall back to the user home or root as baseDir when resolution fails

Example fix

// before
resp, err := FetchSuggestions(ctx, wshrpc.FetchSuggestionsData{SuggestionType: "file", FileCwd: "~", Query: "~/x"})
// after
home, _ := os.UserHomeDir()
resp, err := FetchSuggestions(ctx, wshrpc.FetchSuggestionsData{SuggestionType: "file", FileCwd: home, Query: filepath.Join(home, "x")})
Defensive patterns

Strategy: try-catch

Validate before calling

if _, err := wavebase.ExpandHomeDir(cwd); err != nil {
    return fmt.Errorf("base dir will fail to resolve: %w", err)
}

Try / catch

resp, err := FetchSuggestions(ctx, data)
if err != nil && strings.Contains(err.Error(), "error resolving base dir") {
    data.FileCwd = "/"; data.Query = ""
    resp, err = FetchSuggestions(ctx, data)
}

Prevention

When it happens

Trigger: Any resolveFileQuery failure during a file-type FetchSuggestions call: HOME unset with tilde cwd/query, malformed relative paths, non-expandable tilde queries.

Common situations: Headless deployments without HOME, remote connections whose cwd no longer exists, clients sending query strings with '~' that cannot be expanded.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/468efa4615689c0a. Report an issue: GitHub.