{"record":{"id":"6e64edd4d64c725c","repo":"github/copilot-sdk","slug":"failed-to-close-output-file-w","errorCode":null,"errorMessage":"failed to close output file: %w","messagePattern":"failed to close output file: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/cmd/bundler/main.go","lineNumber":1188,"sourceCode":"\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to read tar: %w\", err)\n\t\t}\n\n\t\tif header.Name == targetPath {\n\t\t\toutPath := filepath.Join(destDir, outputName)\n\t\t\toutFile, err := os.OpenFile(outPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.FileMode(header.Mode))\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to create output file: %w\", err)\n\t\t\t}\n\n\t\t\tif _, err := io.Copy(outFile, tarReader); err != nil {\n\t\t\t\tif cerr := outFile.Close(); cerr != nil {\n\t\t\t\t\treturn fmt.Errorf(\"failed to extract binary (copy error: %v, close error: %v)\", err, cerr)\n\t\t\t\t}\n\t\t\t\treturn fmt.Errorf(\"failed to extract binary: %w\", err)\n\t\t\t}\n\t\t\tif err := outFile.Close(); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to close output file: %w\", err)\n\t\t\t}\n\t\t\treturn nil\n\t\t}\n\t}\n\n\treturn fmt.Errorf(\"file %q not found in tarball\", targetPath)\n}\n\n// extractOptionalFileFromTarball extracts a single file from a .tgz into destDir\n// like extractFileFromTarball, but returns (false, nil) instead of an error when\n// the file is absent. Used for the runtime library, which older CLI packages do\n// not ship.\nfunc extractOptionalFileFromTarball(tarballPath, destDir, targetPath, outputName string) (bool, error) {\n\terr := extractFileFromTarball(tarballPath, destDir, targetPath, outputName)\n\tif err == nil {\n\t\treturn true, nil\n\t}\n\tif strings.Contains(err.Error(), \"not found in tarball\") {","sourceCodeStart":1170,"sourceCodeEnd":1206,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/cmd/bundler/main.go#L1170-L1206","documentation":"extractFileFromTarball extracts a named file from a .tgz archive by copying it to an output file. After the copy succeeds, the function closes the file and surfaces any close error (e.g. buffered data not flushed to disk, ENOSPC) wrapped with this message. It guarantees the extracted file is fully persisted before returning success.","triggerScenarios":"The tar entry was found and copied via io.Copy without error, but outFile.Close() returns a non-nil error — typically because the write data could not be flushed to disk (disk full, I/O error, or network filesystem failure) on Close.","commonSituations":"Disk quota or free-space exhaustion on the machine running bundler; write failures on NFS/overlay filesystems where errors are reported at close rather than write; extracting large CLI binaries to a nearly-full volume.","solutions":["Check free disk space on the destination volume (df -h) and free up space","Retry the bundling step; transient I/O errors may not recur","Check dmesg / system logs for underlying disk I/O errors","If on a network filesystem, extract to a local temp dir instead"],"exampleFix":"// before\nif err := outFile.Close(); err != nil {\n\treturn fmt.Errorf(\"failed to close output file: %w\", err)\n}\n// after\nif err := outFile.Close(); err != nil {\n\tif errors.Is(err, syscall.ENOSPC) {\n\t\treturn fmt.Errorf(\"failed to close output file: %w (disk full — free up space and retry)\", err)\n\t}\n\treturn fmt.Errorf(\"failed to close output file: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// check writable space/permissions on destination before extracting\ndu, _ := statfs(destDir)\nif du.Available < minRequiredBytes { return errors.New(\"insufficient disk space\") }\n","typeGuard":null,"tryCatchPattern":"// Go\ntgz, err := extractFileFromTarball(tgzPath, target, destDir)\nif err != nil && strings.Contains(err.Error(), \"failed to close output file\") {\n\t// free disk space or switch to a local filesystem, then retry\n}","preventionTips":["Monitor free disk space on the extraction volume before bundling","Extract to a local (non-network) filesystem","Keep disk usage alerts configured on build machines"],"tags":["filesystem","tarball","io"],"backgroundTag":"file-write-failed","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}