wavetermdev/waveterm · error
adding file %s: %w
Error message
adding file %s: %w
What it means
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".
Source
Thrown at cmd/wsh/cmd/wshcmd-ai.go:192
err := wshclient.WaveAIAddContextCommand(RpcClient, newChatData, &wshrpc.RpcOpts{
Route: route,
Timeout: rpcTimeout,
})
if err != nil {
return fmt.Errorf("creating new chat: %w", err)
}
}
for _, file := range allFiles {
contextData := wshrpc.CommandWaveAIAddContextData{
Files: []wshrpc.AIAttachedFile{file},
}
err := wshclient.WaveAIAddContextCommand(RpcClient, contextData, &wshrpc.RpcOpts{
Route: route,
Timeout: rpcTimeout,
})
if err != nil {
return fmt.Errorf("adding file %s: %w", file.Name, err)
}
}
if aiMessageFlag != "" || aiSubmitFlag {
finalContextData := wshrpc.CommandWaveAIAddContextData{
Text: aiMessageFlag,
Submit: aiSubmitFlag,
}
err := wshclient.WaveAIAddContextCommand(RpcClient, finalContextData, &wshrpc.RpcOpts{
Route: route,
Timeout: rpcTimeout,
})
if err != nil {
return fmt.Errorf("adding context: %w", err)
}
}
return nilView on GitHub (pinned to a4447c1563)
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.
Example fix
// before wsh ai --file ./src/oldname.go // error: adding file ./src/oldname.go: ... // after wsh ai --file ./src/renamed.go
Defensive patterns
Strategy: validation
Validate before calling
info, err := os.Stat(path)
if err != nil || info.IsDir() {
// skip or fix the --file path before invoking wsh ai
} Try / catch
if err != nil {
var wrappedErr = fmt.Errorf("adding file %s: %w", file.Name, err)
// log file.Name and retry only the failed file
} Prevention
- Stat each --file path before passing it to wsh ai.
- Use absolute paths to avoid cwd mismatch.
- Keep attachments within size limits.
When it happens
Trigger: `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).
Common situations: 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.
Related errors
- source cannot be blank
- nil wshrpc passed to wshclient
- creating new chat: %w
- adding context: %w
- publishing badge event: %v
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/3024c52dacfb0ea7.
Report an issue: GitHub.