{"record":{"id":"c4243c4f33730a59","repo":"github/copilot-sdk","slug":"failed-to-create-tarball-file-w","errorCode":null,"errorMessage":"failed to create tarball file: %w","messagePattern":"failed to create tarball file: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/cmd/bundler/main.go","lineNumber":1016,"sourceCode":"\ttarballURL := releaseDownloadURL(cliVersion, assetName)\n\n\tfmt.Printf(\"Downloading from %s...\\n\", tarballURL)\n\n\tresp, err := releaseHTTPClient.Get(tarballURL)\n\tif err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"failed to download: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\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)","sourceCodeStart":998,"sourceCodeEnd":1034,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/cmd/bundler/main.go#L998-L1034","documentation":"After a successful download response, downloadCLIBinary creates the destination tarball file in destDir and wraps os.Create failures in this error. The tarball must be persisted to disk for hashing and later extraction, so failure aborts the build.","triggerScenarios":"os.Create(filepath.Join(destDir, assetName)) fails: destDir doesn't exist, no write permission, disk full, or the path is invalid (e.g. assetName containing path separators on some filesystems).","commonSituations":"Temp/output directory deleted or never created; read-only filesystem or full disk in CI; overly restrictive umask/permissions; assetName containing characters illegal for the local filesystem.","solutions":["Ensure destDir exists before calling downloadCLIBinary (os.MkdirAll with 0o755)","Check write permissions and free disk space on destDir","Sanitize assetName to a safe filename before joining with destDir","Inspect the wrapped cause (%w) for the exact syscall error"],"exampleFix":"// before\ntarballPath := filepath.Join(destDir, assetName)\ntarballFile, err := os.Create(tarballPath)\nif err != nil {\n\treturn \"\", \"\", fmt.Errorf(\"failed to create tarball file: %w\", err)\n}\n// after\nif err := os.MkdirAll(destDir, 0o755); err != nil {\n\treturn \"\", \"\", fmt.Errorf(\"failed to create dest dir: %w\", err)\n}\ntarballPath := filepath.Join(destDir, filepath.Base(assetName))\ntarballFile, err := os.Create(tarballPath)\nif err != nil {\n\treturn \"\", \"\", fmt.Errorf(\"failed to create tarball file: %w\", err)\n}","handlingStrategy":"validation","validationCode":"if err := os.MkdirAll(destDir, 0o755); err != nil {\n\treturn fmt.Errorf(\"dest dir not usable: %w\", err)\n}\nprobe := filepath.Join(destDir, \".write-probe\")\nif err := os.WriteFile(probe, nil, 0o644); err != nil {\n\treturn fmt.Errorf(\"dest dir not writable: %w\", err)\n}\nos.Remove(probe)","typeGuard":"func dirIsWritable(dir string) bool {\n\tfi, err := os.Stat(dir)\n\treturn err == nil && fi.IsDir() && unix.Access(dir, unix.W_OK) == nil\n}","tryCatchPattern":"tarballFile, err := os.Create(tarballPath)\nif err != nil {\n\tif os.IsPermission(err) {\n\t\t// fix permissions or choose another destDir\n\t}\n\treturn \"\", \"\", fmt.Errorf(\"failed to create tarball file: %w\", err)\n}\ndefer tarballFile.Close()","preventionTips":["Always os.MkdirAll the destination directory before writing","Check free disk space before downloading large assets","Use filepath.Base(assetName) to avoid path-separator surprises","Ensure build users have write access to the temp/output directories"],"tags":["go","filesystem","file-write","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"}