{"record":{"id":"c42d49b2f75a18c1","repo":"github/copilot-sdk","slug":"failed-to-close-tarball-file-w","errorCode":null,"errorMessage":"failed to close tarball file: %w","messagePattern":"failed to close tarball file: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/cmd/bundler/main.go","lineNumber":1025,"sourceCode":"\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to download: %s\", resp.Status)\n\t}\n\n\t// Save tarball to temp file\n\ttarballPath := filepath.Join(destDir, assetName)\n\ttarballFile, err := os.Create(tarballPath)\n\tif err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to create tarball file: %w\", err)\n\t}\n\n\thasher := sha256.New()\n\tif _, err := io.Copy(io.MultiWriter(tarballFile, hasher), resp.Body); err != nil {\n\t\ttarballFile.Close()\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to save tarball: %w\", err)\n\t}\n\tif err := tarballFile.Close(); err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to close tarball file: %w\", err)\n\t}\n\tactualChecksum := fmt.Sprintf(\"%x\", hasher.Sum(nil))\n\tif actualChecksum != expectedChecksum {\n\t\treturn \"\", \"\", fmt.Errorf(\n\t\t\t\"checksum mismatch for %s: expected %s, got %s\",\n\t\t\tassetName,\n\t\t\texpectedChecksum,\n\t\t\tactualChecksum,\n\t\t)\n\t}\n\n\t// The SDK release package intentionally omits the legacy SEA binary. Preserve\n\t// embeddedcli.Path compatibility by installing the runtime wrapper under the\n\t// historical copilot[.exe] name; the normal client path uses the adjacent\n\t// wrapper/runtime.node pair directly.\n\tbinaryPath := filepath.Join(destDir, binaryName)\n\twrapperName := runtimeWrapperName(binaryName)\n\tif err := extractFileFromTarball(","sourceCodeStart":1007,"sourceCodeEnd":1043,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/cmd/bundler/main.go#L1007-L1043","documentation":"After the tarball body is fully copied, downloadCLIBinary closes the tarball file to flush buffered data to disk. If file.Close() fails (flush error, disk full, I/O error), this error wraps it. It exists because Close can fail even when all writes succeeded, and the checksum would otherwise be computed against a partially flushed file.","triggerScenarios":"tarballFile.Close() returns non-nil after io.Copy completed — typically ENOSPC on flush, an I/O error on the underlying filesystem, or (on NFS/network mounts) stale handle errors.","commonSituations":"Disk filling up between file creation and close; building bundles onto a flaky NFS mount or full Docker volume; container filesystem hitting quota.","solutions":["Free disk space on the target filesystem and re-run buildBundle.","Check filesystem health (dmesg / fsck) if close errors persist.","Redirect output (TMPDIR / output dir) to a local, non-network filesystem.","Retry the build after resolving the underlying I/O condition."],"exampleFix":"// before: default temp dir may be on a small tmpfs\n// after: point TMPDIR at a filesystem with headroom\nos.Setenv(\"TMPDIR\", \"/var/tmp\")\ntarballPath, _, err := downloadCLIBinary(...)","handlingStrategy":"try-catch","validationCode":"if st, err := os.Statfs(filepath.Dir(tarballPath)); err == nil && st.Avail < tarballSizeEstimate {\n    return fmt.Errorf(\"not enough space to flush tarball\")\n}","typeGuard":null,"tryCatchPattern":"if _, _, err := downloadCLIBinary(...); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && errors.Is(pe.Err, syscall.ENOSPC) {\n        freeSpaceAndRetry()\n    }\n}","preventionTips":["Always check Close() errors on files you write (the bundler does).","Point TMPDIR at local, non-quota filesystems.","Clean old bundle artifacts to avoid disk exhaustion.","Avoid network filesystems for build temp directories."],"tags":["io","filesystem","go","download"],"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-15T23:17:13.987Z"}