wavetermdev/waveterm · error

appending chunk to file: %w

Error message

appending chunk to file: %w

What it means

After each 32KB chunk read, streamWriteToFile sends it via FileAppendCommand. A failure on any chunk mid-stream is wrapped as "appending chunk to file", meaning the destination file was truncated and only partially written.

Source

Thrown at cmd/wsh/cmd/wshcmd-file-util.go:86

		}
		if err != nil {
			return fmt.Errorf("reading input: %w", err)
		}

		// Check total size
		totalWritten += int64(n)
		if totalWritten > MaxFileSize {
			return fmt.Errorf("input exceeds maximum file size of %d bytes", MaxFileSize)
		}

		// Prepare and send chunk
		chunk := buf[:n]
		appendData := fileData
		appendData.Data64 = base64.StdEncoding.EncodeToString(chunk)

		err = wshclient.FileAppendCommand(RpcClient, appendData, &wshrpc.RpcOpts{Timeout: int64(fileTimeout)})
		if err != nil {
			return fmt.Errorf("appending chunk to file: %w", err)
		}
	}

	return nil
}

func streamReadFromFile(ctx context.Context, fileData wshrpc.FileData, writer io.Writer) error {
	broker := RpcClient.StreamBroker
	if broker == nil {
		return fmt.Errorf("stream broker not available")
	}
	if fileData.Info == nil {
		return fmt.Errorf("file info is required")
	}
	readerRouteId := RpcClientRouteId
	if readerRouteId == "" {
		return fmt.Errorf("no route id available")
	}

View on GitHub (pinned to a4447c1563)

Solutions

  1. Retry the whole streaming command — the file is re-truncated at the start of each attempt, avoiding partial data.
  2. Check free disk space/quota on the destination host.
  3. Increase fileTimeout for high-latency connections.
  4. For large/unreliable transfers, use resumable tools (rsync over ssh) instead of wsh streaming.
Defensive patterns

Strategy: retry

Validate before calling

// pre-check destination capacity if accessible
if df, err := exec.Command("sh", "-c", "df -k $(dirname "+path+")").Output(); err == nil {
    // abort early if low disk space
}

Try / catch

err := streamWriteToFile(fileData, reader)
for retries := 0; err != nil && retries < 3; retries++ {
    time.Sleep(time.Duration(1<<retries) * time.Second) // restart re-truncates file
    err = streamWriteToFile(fileData, reader)
}

Prevention

When it happens

Trigger: FileAppendCommand fails partway through streaming: RPC timeout (fileTimeout) on a slow link, connection drop mid-transfer, or server-side write failure (disk full, permission revoked).

Common situations: Transferring a large file over a flaky SSH/remote connection; disk quota exceeded on the remote host mid-write; network hiccup after several minutes of transfer.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/7e36f50f113b7d3a. Report an issue: GitHub.