{"record":{"id":"30e24db7b75ec395","repo":"wavetermdev/waveterm","slug":"error-expanding-query-home-dir-w","errorCode":null,"errorMessage":"error expanding query home dir: %w","messagePattern":"error expanding query home dir: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/suggestion/suggestion.go","lineNumber":83,"sourceCode":"\t// If no current working directory, default to \"~\".\n\tif cwd == \"\" {\n\t\tcwd = \"~\"\n\t}\n\tvar err error\n\tcwd, err = wavebase.ExpandHomeDir(cwd)\n\tif err != nil {\n\t\treturn \"\", \"\", \"\", fmt.Errorf(\"error expanding home dir: %w\", err)\n\t}\n\tif query == \"\" {\n\t\treturn cwd, \"\", \"\", nil\n\t}\n\t// Expand home if needed.\n\ttildeSlash := \"~\" + PathSepStr\n\tif query == \"~\" || strings.HasPrefix(query, tildeSlash) {\n\t\togQuery := query\n\t\tquery, err = wavebase.ExpandHomeDir(query)\n\t\tif err != nil {\n\t\t\treturn \"\", \"\", \"\", fmt.Errorf(\"error expanding query home dir: %w\", err)\n\t\t}\n\t\tif ogQuery == \"~\" || ogQuery == tildeSlash {\n\t\t\treturn query, tildeSlash, \"\", nil\n\t\t}\n\t}\n\t// Handle absolute queries.\n\tif filepath.IsAbs(query) {\n\t\tif filepath.Dir(query) == query {\n\t\t\treturn query, query, \"\", nil\n\t\t}\n\t\tif strings.HasSuffix(query, PathSepStr) {\n\t\t\t// Remove trailing slash for canonical directory path.\n\t\t\tbaseDir := strings.TrimRight(query, PathSepStr)\n\t\t\t// But keep the trailing slash in the queryPrefix for display.\n\t\t\tqueryPrefix := query\n\t\t\treturn baseDir, queryPrefix, \"\", nil\n\t\t}\n\t\t// Otherwise, e.g. \"/var/f\"","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/suggestion/suggestion.go#L65-L101","documentation":"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.","triggerScenarios":"FetchSuggestions with SuggestionType \"file\" and a Query like \"~/docs\" while ExpandHomeDir fails (HOME unset, user lookup error).","commonSituations":"Headless environments without HOME, remote connections where the user's home cannot be resolved, malformed queries combining '~' with a nonexistent user (e.g. '~baduser/').","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"],"exampleFix":"// before\nquery := \"~/projects\"\nresp, err := FetchSuggestions(ctx, wshrpc.FetchSuggestionsData{SuggestionType: \"file\", Query: query})\n// after\nhome, _ := os.UserHomeDir()\nresp, err := FetchSuggestions(ctx, wshrpc.FetchSuggestionsData{SuggestionType: \"file\", Query: filepath.Join(home, \"projects\")})","handlingStrategy":"validation","validationCode":"if strings.HasPrefix(query, \"~\") && os.Getenv(\"HOME\") == \"\" {\n    return errors.New(\"query uses ~ but HOME is not set\")\n}","typeGuard":"func isTildeQuery(q string) bool { return q == \"~\" || strings.HasPrefix(q, \"~/\") }","tryCatchPattern":"expanded, err := wavebase.ExpandHomeDir(query)\nif err != nil {\n    log.Printf(\"tilde expansion failed for %q: %v\", query, err)\n    return fallbackSuggestions\n}","preventionTips":["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"],"tags":["go","environment","path-expansion"],"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"}