{"record":{"id":"468efa4615689c0a","repo":"wavetermdev/waveterm","slug":"error-resolving-base-dir-w","errorCode":null,"errorMessage":"error resolving base dir: %w","messagePattern":"error resolving base dir: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/suggestion/suggestion.go","lineNumber":369,"sourceCode":"func (h *scoredEntryHeap) Push(x interface{}) { *h = append(*h, x.(scoredEntry)) }\nfunc (h *scoredEntryHeap) Pop() interface{} {\n\told := *h\n\tn := len(old)\n\tx := old[n-1]\n\t*h = old[0 : n-1]\n\treturn x\n}\n\nfunc fetchFileSuggestions(ctx context.Context, data wshrpc.FetchSuggestionsData) (*wshrpc.FetchSuggestionsResponse, error) {\n\t// Only support file suggestions.\n\tif data.SuggestionType != \"file\" {\n\t\treturn nil, fmt.Errorf(\"unsupported suggestion type: %q\", data.SuggestionType)\n\t}\n\n\t// Resolve the base directory, query prefix (for display) and search term.\n\tbaseDir, queryPrefix, searchTerm, err := resolveFileQuery(data.FileCwd, data.Query)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error resolving base dir: %w\", err)\n\t}\n\n\t// Use a cancellable context for directory listing.\n\tlistingCtx, cancelFn := context.WithCancel(ctx)\n\tdefer cancelFn()\n\n\tentriesCh, err := listDirectory(listingCtx, data.WidgetId, baseDir, 1000)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error listing directory: %w\", err)\n\t}\n\n\tconst maxEntries = MaxSuggestions // top-k entries\n\n\t// Always use a heap.\n\tvar topHeap scoredEntryHeap\n\theap.Init(&topHeap)\n\n\tvar patternRunes []rune","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/suggestion/suggestion.go#L351-L387","documentation":"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.","triggerScenarios":"Any resolveFileQuery failure during a file-type FetchSuggestions call: HOME unset with tilde cwd/query, malformed relative paths, non-expandable tilde queries.","commonSituations":"Headless deployments without HOME, remote connections whose cwd no longer exists, clients sending query strings with '~' that cannot be expanded.","solutions":["Inspect the wrapped inner error (%w chain) to find whether it is the cwd (line 72) or query (line 83) expansion failing","Fix HOME environment or pass absolute FileCwd/Query values","Fall back to the user home or root as baseDir when resolution fails"],"exampleFix":"// before\nresp, err := FetchSuggestions(ctx, wshrpc.FetchSuggestionsData{SuggestionType: \"file\", FileCwd: \"~\", Query: \"~/x\"})\n// after\nhome, _ := os.UserHomeDir()\nresp, err := FetchSuggestions(ctx, wshrpc.FetchSuggestionsData{SuggestionType: \"file\", FileCwd: home, Query: filepath.Join(home, \"x\")})","handlingStrategy":"try-catch","validationCode":"if _, err := wavebase.ExpandHomeDir(cwd); err != nil {\n    return fmt.Errorf(\"base dir will fail to resolve: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"resp, err := FetchSuggestions(ctx, data)\nif err != nil && strings.Contains(err.Error(), \"error resolving base dir\") {\n    data.FileCwd = \"/\"; data.Query = \"\"\n    resp, err = FetchSuggestions(ctx, data)\n}","preventionTips":["Pre-resolve cwd/tilde paths with ExpandHomeDir before calling FetchSuggestions","Unwrap the error chain with errors.As/Unwrap to identify the true cause","Provide a safe fallback baseDir (home or root) when resolution fails"],"tags":["go","path-resolution","suggestions"],"backgroundTag":"home-dir-resolution-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}