d2lang/d2 · error
error copying %s: %v
Error message
error copying %s: %v
What it means
copyPptxTemplateTo copies every non-skipped file from the embedded pptx template zip into the output zip via w.Copy(f); if any single entry fails to copy, the operation aborts with this error naming the entry. It indicates the output pptx would be incomplete or corrupt.
Source
Thrown at lib/pptx/pptx.go:303
func copyPptxTemplateTo(w *zip.Writer) error {
reader := bytes.NewReader(PPTX_TEMPLATE)
zipReader, err := zip.NewReader(reader, reader.Size())
if err != nil {
fmt.Printf("error creating zip reader: %v", err)
}
skipFiles := map[string]bool{
"_rels/.rels": true,
"ppt/slideMasters/_rels/slideMaster1.xml.rels": true,
}
for _, f := range zipReader.File {
if skipFiles[f.Name] {
continue
}
if err := w.Copy(f); err != nil {
return fmt.Errorf("error copying %s: %v", f.Name, err)
}
}
return nil
}
//go:embed templates/slide.xml.rels
var RELS_SLIDE_XML string
type RelsSlideXmlLinkContent struct {
RelationshipID string
ExternalUrl string
SlideIndex int
}
type RelsSlideXmlContent struct {
FileName string
RelationshipID string
Links []RelsSlideXmlLinkContentView on GitHub (pinned to 0d69dca6f5)
Solutions
- Check disk space and write permissions for the output path in SaveTo
- Close the pptx file in other programs and retry
- Verify the wrapped error (%v) identifies the zip writer cause
- Retry the save; transient I/O errors often resolve
- If custom skipFiles/template edits were made, verify the template zip integrity
Example fix
// before
err := pres.SaveTo(f)
// after
err := pres.SaveTo(f)
if err != nil && strings.Contains(err.Error(), "error copying") {
log.Printf("template copy failed: %v — check disk space / file locks", err)
} Defensive patterns
Strategy: try-catch
Validate before calling
if st, err := os.Stat(outPath); err == nil { f, _ := os.OpenFile(outPath, os.O_WRONLY, 0); if f != nil { f.Close() } } // writability check Type guard
func isCopyError(err error) bool { return strings.Contains(err.Error(), "error copying ") } Try / catch
err := pres.SaveTo(out)
if err != nil {
if isCopyError(err) {
log.Printf("pptx write failed: %v — check disk space and file locks", err)
return retrySave(out)
}
return err
} Prevention
- Check free disk space before large exports
- Never write to a pptx open in PowerPoint
- Close file handles and flush writers before SaveTo
- Save to a temp file then rename for atomicity
When it happens
Trigger: w.Copy(f) fails for a template entry — typically an underlying zip writer error such as the destination writer being closed, an I/O failure, or a corrupted template zip entry.
Common situations: Disk full or permission denied when writing SaveTo's destination; destination file locked by another process (e.g. PowerPoint open); corrupted embedded template.
Related errors
- cannot read a directory
- error decoding PNG image: %v
- no color stops in gradient
- %s is not a supported format. Supported formats are: %s
- failed to fully compile (partial render written) %s: %w
AI-assisted analysis of d2lang/d2@0d69dca6f5 (2026-08-31).
Data as JSON: /api/errors/8e7fee39ea367a28.
Report an issue: GitHub.