{"record":{"id":"3024c52dacfb0ea7","repo":"wavetermdev/waveterm","slug":"adding-file-s-w","errorCode":null,"errorMessage":"adding file %s: %w","messagePattern":"adding file (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-ai.go","lineNumber":192,"sourceCode":"\t\terr := wshclient.WaveAIAddContextCommand(RpcClient, newChatData, &wshrpc.RpcOpts{\n\t\t\tRoute:   route,\n\t\t\tTimeout: rpcTimeout,\n\t\t})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"creating new chat: %w\", err)\n\t\t}\n\t}\n\n\tfor _, file := range allFiles {\n\t\tcontextData := wshrpc.CommandWaveAIAddContextData{\n\t\t\tFiles: []wshrpc.AIAttachedFile{file},\n\t\t}\n\t\terr := wshclient.WaveAIAddContextCommand(RpcClient, contextData, &wshrpc.RpcOpts{\n\t\t\tRoute:   route,\n\t\t\tTimeout: rpcTimeout,\n\t\t})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"adding file %s: %w\", file.Name, err)\n\t\t}\n\t}\n\n\tif aiMessageFlag != \"\" || aiSubmitFlag {\n\t\tfinalContextData := wshrpc.CommandWaveAIAddContextData{\n\t\t\tText:   aiMessageFlag,\n\t\t\tSubmit: aiSubmitFlag,\n\t\t}\n\t\terr := wshclient.WaveAIAddContextCommand(RpcClient, finalContextData, &wshrpc.RpcOpts{\n\t\t\tRoute:   route,\n\t\t\tTimeout: rpcTimeout,\n\t\t})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"adding context: %w\", err)\n\t\t}\n\t}\n\n\treturn nil","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-ai.go#L174-L210","documentation":"For each file collected via --file flags, aiRun sends a WaveAIAddContextCommand RPC attaching that file to the AI chat. Failure of any per-file RPC is wrapped with the file name: \"adding file %s: %w\".","triggerScenarios":"`wsh ai --file <path>` where the file cannot be attached: path does not exist or is unreadable, file too large, or the WaveAIAddContextCommand RPC fails (bad route, timeout, server rejection).","commonSituations":"Typo or stale path in --file argument; file deleted after being staged; attaching files from a directory the Wave process cannot read; oversized file exceeding context limits.","solutions":["Check the named file exists and is readable (`ls -l <file>`); fix the path and re-run.","Verify the AI chat block target still exists (tab wasn't closed).","Reduce file size/count if the server rejected the attachment.","Read the wrapped cause for the specific RPC-level failure and address it."],"exampleFix":"// before\nwsh ai --file ./src/oldname.go\n// error: adding file ./src/oldname.go: ...\n\n// after\nwsh ai --file ./src/renamed.go","handlingStrategy":"validation","validationCode":"info, err := os.Stat(path)\nif err != nil || info.IsDir() {\n    // skip or fix the --file path before invoking wsh ai\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    var wrappedErr = fmt.Errorf(\"adding file %s: %w\", file.Name, err)\n    // log file.Name and retry only the failed file\n}","preventionTips":["Stat each --file path before passing it to wsh ai.","Use absolute paths to avoid cwd mismatch.","Keep attachments within size limits."],"tags":["rpc","wsh","file-attachment"],"backgroundTag":"rpc-call-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}