{"record":{"id":"8e7fee39ea367a28","repo":"d2lang/d2","slug":"error-copying-s-v","errorCode":null,"errorMessage":"error copying %s: %v","messagePattern":"error copying (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/pptx/pptx.go","lineNumber":303,"sourceCode":"\nfunc copyPptxTemplateTo(w *zip.Writer) error {\n\treader := bytes.NewReader(PPTX_TEMPLATE)\n\tzipReader, err := zip.NewReader(reader, reader.Size())\n\tif err != nil {\n\t\tfmt.Printf(\"error creating zip reader: %v\", err)\n\t}\n\n\tskipFiles := map[string]bool{\n\t\t\"_rels/.rels\": true,\n\t\t\"ppt/slideMasters/_rels/slideMaster1.xml.rels\": true,\n\t}\n\n\tfor _, f := range zipReader.File {\n\t\tif skipFiles[f.Name] {\n\t\t\tcontinue\n\t\t}\n\t\tif err := w.Copy(f); err != nil {\n\t\t\treturn fmt.Errorf(\"error copying %s: %v\", f.Name, err)\n\t\t}\n\t}\n\treturn nil\n}\n\n//go:embed templates/slide.xml.rels\nvar RELS_SLIDE_XML string\n\ntype RelsSlideXmlLinkContent struct {\n\tRelationshipID string\n\tExternalUrl    string\n\tSlideIndex     int\n}\n\ntype RelsSlideXmlContent struct {\n\tFileName       string\n\tRelationshipID string\n\tLinks          []RelsSlideXmlLinkContent","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/lib/pptx/pptx.go#L285-L321","documentation":"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.","triggerScenarios":"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.","commonSituations":"Disk full or permission denied when writing SaveTo's destination; destination file locked by another process (e.g. PowerPoint open); corrupted embedded template.","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"],"exampleFix":"// before\nerr := pres.SaveTo(f)\n// after\nerr := pres.SaveTo(f)\nif err != nil && strings.Contains(err.Error(), \"error copying\") {\n    log.Printf(\"template copy failed: %v — check disk space / file locks\", err)\n}","handlingStrategy":"try-catch","validationCode":"if st, err := os.Stat(outPath); err == nil { f, _ := os.OpenFile(outPath, os.O_WRONLY, 0); if f != nil { f.Close() } } // writability check","typeGuard":"func isCopyError(err error) bool { return strings.Contains(err.Error(), \"error copying \") }","tryCatchPattern":"err := pres.SaveTo(out)\nif err != nil {\n    if isCopyError(err) {\n        log.Printf(\"pptx write failed: %v — check disk space and file locks\", err)\n        return retrySave(out)\n    }\n    return err\n}","preventionTips":["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"],"tags":["go","zip","pptx","io","template"],"backgroundTag":"zip-copy-failed","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}