wavetermdev/waveterm · error
file %s exceeds maximum size of %s for %s files
Error message
file %s exceeds maximum size of %s for %s files
What it means
`wsh ai` enforces per-type size limits via getMaxFileSize: 5MB for PDFs, 7MB for images, 200KB for everything else (plain text and directory listings). Files are base64-encoded into one RPC payload, so oversized attachments are rejected before the RPC is sent. fileName is the absolute path or "stdin"; sizeStr names the limit.
Source
Thrown at cmd/wsh/cmd/wshcmd-ai.go:152
fileName = absPath
mimeType = detectMimeType(data)
}
}
isPDF := mimeType == "application/pdf"
isImage := strings.HasPrefix(mimeType, "image/")
isDirectory := mimeType == "directory"
if !isPDF && !isImage && !isDirectory {
mimeType = "text/plain"
if utilfn.ContainsBinaryData(data) {
return fmt.Errorf("file %s contains binary data and cannot be uploaded as text", fileName)
}
}
maxSize, sizeStr := getMaxFileSize(mimeType)
if len(data) > maxSize {
return fmt.Errorf("file %s exceeds maximum size of %s for %s files", fileName, sizeStr, mimeType)
}
allFiles = append(allFiles, wshrpc.AIAttachedFile{
Name: fileName,
Type: mimeType,
Size: len(data),
Data64: base64.StdEncoding.EncodeToString(data),
})
}
tabId := os.Getenv("WAVETERM_TABID")
if tabId == "" {
return fmt.Errorf("WAVETERM_TABID environment variable not set")
}
route := wshutil.MakeTabRouteId(tabId)
if aiNewBlockFlag {View on GitHub (pinned to a4447c1563)
Solutions
- Trim the file to the relevant portion: `tail -n 500 build.log > recent.log` (or head/grep) and attach the smaller file.
- Compress text with relevance filtering: `grep -i error build.log | wsh ai -` or pipe through `| head -c 200000 | wsh ai -`.
- For images, downscale/re-encode below 7MB (e.g. `convert img.png -resize 50% img.png`) or use JPEG.
- For PDFs, split or compress below 5MB (e.g. `qpdf --split-pages` or ghostscript compression).
- For directory listings exceeding 200KB of JSON, attach a narrower subdirectory or specific files instead.
Example fix
// before $ wsh ai build.log // error: file /path/build.log exceeds maximum size of 200KB for text/plain files // after $ grep -iE 'error|fail' build.log | wsh ai - --message "why did the build fail?"
Defensive patterns
Strategy: validation
Validate before calling
limit() { case "$1" in *.pdf) echo 5242880 ;; *.png|*.jpg|*.jpeg|*.gif|*.webp) echo 7340032 ;; *) echo 204800 ;; esac; }
for f in "$@"; do
[ "$f" = "-" ] && continue
max=$(limit "$f")
size=$(stat -c%s "$f")
if [ "$size" -gt "$max" ]; then
echo "too large: $f ($size > $max bytes); trim or compress first" >&2
exit 1
fi
done Try / catch
if err := runAI(args); err != nil {
if strings.Contains(err.Error(), "exceeds maximum size") {
return fmt.Errorf("trim/compress the file (tail -n 500, image resize, pdf split) below the per-type cap")
}
return err
} Prevention
- Remember the caps: 200KB text, 5MB PDF, 7MB image — check with `stat -c%s` (or `ls -l`) before attaching.
- Attach filtered excerpts of logs (grep/tail) rather than full multi-MB logs.
- Pre-resize images and split/compress large PDFs as a pipeline step.
- Account for base64 overhead by keeping inputs well under the limits, and remember directory listings share the 200KB cap.
When it happens
Trigger: Attaching any file whose byte length exceeds the applicable cap: a text/log/source file over 200KB (e.g. big logs, minified JS, large JSON), a PDF over 5MB, an image over 7MB, or a stdin stream over its type's cap. Note directories always use the 200KB cap for their JSON listing (max 500 entries).
Common situations: `wsh ai build.log` from a long CI run (often >200KB); attaching high-resolution screenshots >7MB; large generated/minified source files; big dataset excerpts.
Related errors
- append would exceed maximum file size of %d bytes
- Image too large (>5MB)
- file %s contains binary data and cannot be uploaded as text
- unknown --view %q; try one of: term, web, preview, edit, sys
- --workspace and --window are mutually exclusive; specify onl
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/06a5f66711f529af.
Report an issue: GitHub.