{"record":{"id":"210c10189d937609","repo":"wavetermdev/waveterm","slug":"error-expanding-home-dir-w","errorCode":null,"errorMessage":"error expanding home dir: %w","messagePattern":"error expanding home dir: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/suggestion/suggestion.go","lineNumber":72,"sourceCode":"//\n// Our approach is to use the presence of a trailing slash to decide whether\n// to treat the query as a directory listing (searchTerm is empty) or a search\n// filter. (This means that a query of exactly \".\" or \"..\" is treated as a\n// search filter, so that files with a dot in their name––including \"..\"––will\n// be returned.)\n//\n// In addition, if there is a slash anywhere in the query (but not at the end),\n// we treat everything before the last slash as a relative directory to search\n// in, and the portion after the last slash as the search term.\nfunc resolveFileQuery(cwd string, query string) (string, string, string, error) {\n\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) {","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/suggestion/suggestion.go#L54-L90","documentation":"resolveFileQuery expands '~' in the caller-provided cwd via wavebase.ExpandHomeDir; if that expansion fails (typically HOME unset/unresolvable), the underlying error is wrapped with this message. It surfaces environment problems before any path resolution proceeds.","triggerScenarios":"Calling FetchSuggestions with SuggestionType \"file\" and a FileCwd requiring expansion while the process HOME environment variable is empty or invalid.","commonSituations":"Server/daemon contexts running without a HOME env var, containerized deployments missing the user environment, corrupted passwd entries for the current user.","solutions":["Ensure the HOME environment variable is set correctly for the wave process","Pass an explicit absolute cwd in FetchSuggestionsData.FileCwd instead of relying on '~'","Inspect the wrapped ExpandHomeDir error for the root cause (which os/user call failed)"],"exampleFix":"// before\ndata := wshrpc.FetchSuggestionsData{SuggestionType: \"file\", FileCwd: \"~\"}\n// after\nif os.Getenv(\"HOME\") == \"\" {\n    os.Setenv(\"HOME\", \"/home/user\")\n}\ndata := wshrpc.FetchSuggestionsData{SuggestionType: \"file\", FileCwd: \"/home/user/work\"}","handlingStrategy":"validation","validationCode":"if os.Getenv(\"HOME\") == \"\" {\n    return errors.New(\"HOME is not set; tilde cwd cannot be expanded\")\n}\nif _, err := wavebase.ExpandHomeDir(\"~\"); err != nil {\n    return fmt.Errorf(\"home expansion unavailable: %w\", err)\n}","typeGuard":"func homeExpandable() bool { _, err := wavebase.ExpandHomeDir(\"~\"); return err == nil }","tryCatchPattern":"cwd, err := wavebase.ExpandHomeDir(data.FileCwd)\nif err != nil {\n    home, hErr := os.UserHomeDir()\n    if hErr != nil { return err }\n    cwd = home\n}","preventionTips":["Set HOME explicitly in service/container environments running wave","Prefer absolute paths in FileCwd over '~' when the environment is uncertain","Wrap calls so the inner ExpandHomeDir error is visible in logs"],"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"}