{"record":{"id":"26af5ee03d08930c","repo":"wavetermdev/waveterm","slug":"append-would-exceed-maximum-file-size-of-d-bytes","errorCode":null,"errorMessage":"append would exceed maximum file size of %d bytes","messagePattern":"append would exceed maximum file size of (.+?) bytes","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-file.go","lineNumber":298,"sourceCode":"\tif info.Size >= MaxFileSize {\n\t\treturn fmt.Errorf(\"file already at maximum size (%d bytes)\", MaxFileSize)\n\t}\n\n\treader := bufio.NewReader(WrappedStdin)\n\tvar buf bytes.Buffer\n\tremainingSpace := MaxFileSize - info.Size\n\tfor {\n\t\tchunk := make([]byte, 8192)\n\t\tn, err := reader.Read(chunk)\n\t\tif err == io.EOF {\n\t\t\tbreak\n\t\t}\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"reading input: %w\", err)\n\t\t}\n\n\t\tif int64(buf.Len()+n) > remainingSpace {\n\t\t\treturn fmt.Errorf(\"append would exceed maximum file size of %d bytes\", MaxFileSize)\n\t\t}\n\n\t\tbuf.Write(chunk[:n])\n\n\t\tif buf.Len() >= 8192 { // 8KB batch size\n\t\t\tfileData.Data64 = base64.StdEncoding.EncodeToString(buf.Bytes())\n\t\t\terr = wshclient.FileAppendCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: fileTimeout})\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"appending to file: %w\", err)\n\t\t\t}\n\t\t\tremainingSpace -= int64(buf.Len())\n\t\t\tbuf.Reset()\n\t\t}\n\t}\n\n\tif buf.Len() > 0 {\n\t\tfileData.Data64 = base64.StdEncoding.EncodeToString(buf.Bytes())\n\t\terr = wshclient.FileAppendCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: fileTimeout})","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-file.go#L280-L316","documentation":"The append loop checks that the accumulated buffer plus the newly read chunk stays within remainingSpace = MaxFileSize - info.Size. If the append would push the remote file past the 10MB cap, it fails with 'append would exceed maximum file size of %d bytes'. Unlike error 191 (file already full), this fires mid-stream when the incoming data is too large for the remaining capacity.","triggerScenarios":"Piping more than (MaxFileSize - current file size) bytes into 'wsh file append'; the check triggers when buf.Len()+n exceeds remainingSpace, before any batch flush containing the excess.","commonSituations":"Appending a large log/dataset to a file that already holds several MB; long-running append jobs whose input grows past the cap; not realizing the 10MB cap applies to the resulting file, not the appended portion.","solutions":["Pre-check the remote file size and truncate your input to fit the remaining space","Rotate: append to a second file once the first approaches 10MB","Write the whole payload to a fresh file with 'wsh file write' if combined size exceeds 10MB and old content is replaceable"],"exampleFix":"// before\nbig-stream | wsh file append [block] out.bin   # exceeds remaining space\n// after\nhead -c 5000000 big-stream | wsh file append [block] out.bin  # stay under the cap","handlingStrategy":"validation","validationCode":"info, _ := wshclient.FileInfoCommand(RpcClient, wshrpc.CommandFileData{Info: &wshrpc.FileInfo{Path: path}}, &wshrpc.RpcOpts{Timeout: fileTimeout})\ninputSize, _ := streamLen() // e.g. stat of temp input file\nif info.Size+inputSize > 10*1024*1024 {\n    return fmt.Errorf(\"append of %d bytes would exceed cap (file at %d)\", inputSize, info.Size)\n}","typeGuard":"func fitsInCap(current, incoming int64) bool {\n    return current+incoming <= 10*1024*1024\n}","tryCatchPattern":null,"preventionTips":["Compute remaining space (10MB - current size) before appending","Truncate or pre-split input to fit the remaining space","Prefer a fresh 'wsh file write' when combined size exceeds 10MB"],"tags":["file-size","limit","append","validation"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}