apache/answer · error
failed to copy file contents from %s to %s: %w
Error message
failed to copy file contents from %s to %s: %w
What it means
Returned by the copy helper in internal/cli/build.go when io.Copy(dstFile, srcFile) fails after both files were opened. This means an I/O error occurred mid-transfer: a read failure on the source, a write failure on the destination (disk full, quota exceeded), or a close-time flush error. The wrapped error identifies which side failed.
Source
Thrown at internal/cli/build.go:550
} else {
// Open the source file
srcFile, err := sourceFs.Open(srcPath)
if err != nil {
return fmt.Errorf("failed to open source file %s: %w", srcPath, err)
}
defer srcFile.Close()
// Create the destination file
dstFile, err := os.Create(dstPath)
if err != nil {
return fmt.Errorf("failed to create destination file %s: %w", dstPath, err)
}
defer dstFile.Close()
// Copy the file contents
_, err = io.Copy(dstFile, srcFile)
if err != nil {
return fmt.Errorf("failed to copy file contents from %s to %s: %w", srcPath, dstPath, err)
}
}
return nil
})
return err
}
// format plugins dir name from dash to underline
func formatUIPluginsDirName(dirPath string) {
entries, err := os.ReadDir(dirPath)
if err != nil {
fmt.Printf("read ui plugins dir failed: [%s] %s\n", dirPath, err)
return
}
for _, entry := range entries {
if !entry.IsDir() || !strings.Contains(entry.Name(), "-") {View on GitHub (pinned to 3b9f137061)
Solutions
- Check free disk space on the destination volume (df -h) — 'no space left on device' is the most common wrapped error
- Re-run the operation; transient I/O errors on network mounts often resolve on retry
- Check the source file's integrity/readability and the destination device health (dmesg for I/O errors)
- If dstFile is buffered, ensure error handling also covers dstFile.Sync()/Close() results
Defensive patterns
Strategy: retry
Validate before calling
// preflight: check free space on destination before copying
out, err := exec.Command("df", "-h", targetDir).Output()
if err != nil {
log.Printf("could not check disk space: %v", err)
} else {
fmt.Println(string(out))
} Try / catch
for attempt := 0; attempt < 3; attempt++ {
if err := copyFile(srcPath, dstPath); err == nil {
break
} else if attempt == 2 {
return fmt.Errorf("copy from %s to %s failed after retries: %w", srcPath, dstPath, err)
}
time.Sleep(time.Duration(attempt+1) * time.Second)
} Prevention
- Monitor disk space on the destination volume before large asset copies
- Use fsync/Close error checking so buffered write failures surface
- Avoid copying large trees over flaky network mounts; stage locally first
When it happens
Trigger: Disk is full or quota exceeded while writing dstPath; source file shrinks or becomes unreadable during copy; I/O error on the underlying device; rare short-write/pipe errors on network-mounted filesystems.
Common situations: Docker/container image builds exhausting disk space; copying large embedded assets to a nearly-full volume; NFS/EFS mounts dropping mid-copy in CI environments.
Related errors
- failed to open source file %s: %w
- failed to create destination file %s: %w
- validate check exception
- base.request_format_error
- error.password.space_invalid
AI-assisted analysis of apache/answer@3b9f137061 (2026-09-05).
Data as JSON: /api/errors/bf2de5bd63fd7824.
Report an issue: GitHub.