{"record":{"id":"44515797ba656f31","repo":"wavetermdev/waveterm","slug":"failed-to-expand-path-w-445157","errorCode":null,"errorMessage":"failed to expand path: %w","messagePattern":"failed to expand path: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/aiusechat/tools_readfile.go","lineNumber":208,"sourceCode":"\t\treturn true, reason\n\t}\n\n\tif baseName == \".git-credentials\" {\n\t\treturn true, \"Git credentials file\"\n\t}\n\n\treturn false, \"\"\n}\n\nfunc verifyReadTextFileInput(input any, toolUseData *uctypes.UIMessageDataToolUse) error {\n\tparams, err := parseReadTextFileInput(input)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\texpandedPath, err := wavebase.ExpandHomeDir(params.Filename)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to expand path: %w\", err)\n\t}\n\n\tif !filepath.IsAbs(expandedPath) {\n\t\treturn fmt.Errorf(\"path must be absolute, got relative path: %s\", params.Filename)\n\t}\n\n\tif blocked, reason := isBlockedFile(expandedPath); blocked {\n\t\treturn fmt.Errorf(\"access denied: potentially sensitive file: %s\", reason)\n\t}\n\n\tfileInfo, err := os.Stat(expandedPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to stat file: %w\", err)\n\t}\n\n\tif fileInfo.IsDir() {\n\t\treturn fmt.Errorf(\"path is a directory, cannot be read with the read_text_file tool. use the read_dir tool if available to read directories\")\n\t}","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/aiusechat/tools_readfile.go#L190-L226","documentation":"verifyReadTextFileInput calls wavebase.ExpandHomeDir on the filename to resolve ~ and validate the path; if that function errors, the failure is wrapped as \"failed to expand path\". This is a pre-flight validation step before any file is opened.","triggerScenarios":"Passing a malformed path that ExpandHomeDir cannot process (e.g. invalid ~ expansion form like \"~nonexistentuser/...\" depending on home-dir resolution failing).","commonSituations":"Tilde paths referencing users that don't exist on this machine; corrupted HOME environment; paths containing platform-invalid constructs caught during expansion.","solutions":["Use a plain absolute path (\"/home/user/file.txt\") instead of a tilde form.","Verify the home directory referenced by ~ exists and HOME/USERPROFILE resolves.","Inspect the wrapped %w cause for the underlying ExpandHomeDir failure."],"exampleFix":"// before\n{\"filename\": \"~nonexistentuser/data.txt\"}\n// after\n{\"filename\": \"/home/realuser/data.txt\"}","handlingStrategy":"try-catch","validationCode":"// prefer plain absolute paths to avoid expansion entirely\nif strings.HasPrefix(p, \"~\") { /* ensure user exists / HOME is set */ }","typeGuard":null,"tryCatchPattern":"if err := verifyReadTextFileInput(params); err != nil {\n    if strings.HasPrefix(err.Error(), \"failed to expand path\") {\n        // fall back to absolute path form and retry\n    }\n}","preventionTips":["Use absolute paths instead of ~user/... forms","Keep HOME/USERPROFILE env sane in the server environment","Confirm the referenced user exists on the host"],"tags":["filesystem","path-resolution","validation"],"backgroundTag":"path-expansion-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}