{"record":{"id":"5541bee70a02d912","repo":"github/copilot-sdk","slug":"failed-to-write-license-w","errorCode":null,"errorMessage":"failed to write license: %w","messagePattern":"failed to write license: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/cmd/bundler/main.go","lineNumber":1110,"sourceCode":"\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create gzip reader: %w\", err)\n\t}\n\tdefer gzReader.Close()\n\n\ttarReader := tar.NewReader(gzReader)\n\tfor {\n\t\theader, err := tarReader.Next()\n\t\tif err == io.EOF {\n\t\t\tbreak\n\t\t}\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to read tar: %w\", err)\n\t\t}\n\t\tswitch header.Name {\n\t\tcase \"package/LICENSE.md\", \"package/LICENSE\":\n\t\t\tlicenseName := filepath.Base(licensePath)\n\t\t\tif err := extractFileFromTarballStream(tarReader, outputDir, licenseName, os.FileMode(header.Mode)); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to write license: %w\", err)\n\t\t\t}\n\t\t\treturn nil\n\t\t}\n\t}\n\n\treturn fmt.Errorf(\"license file not found in tarball\")\n}\n\nfunc licensePathForOutput(outputPath string) string {\n\tif strings.HasSuffix(outputPath, \".zst\") {\n\t\treturn strings.TrimSuffix(outputPath, \".zst\") + \".license\"\n\t}\n\treturn outputPath + \".license\"\n}\n\nfunc licenseFileName(binaryName string) string {\n\tif strings.HasSuffix(binaryName, \".zst\") {\n\t\treturn strings.TrimSuffix(binaryName, \".zst\") + \".license\"","sourceCodeStart":1092,"sourceCodeEnd":1128,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/cmd/bundler/main.go#L1092-L1128","documentation":"extractCLILicense scans a .tgz tarball for a package/LICENSE.md or package/LICENSE entry and streams it to disk via extractFileFromTarballStream. This error wraps any failure from that write step: the output file could not be created, or the copy/close of its contents failed. The wrapped error identifies the underlying OS or stream problem.","triggerScenarios":"extractCLILicense is called (from buildBundle) with an outputDir that is unwritable, nonexistent, has wrong permissions, or where the destination license name collides with a directory; also on stream read failures mid-copy from the tar reader.","commonSituations":"Running the bundler as a user without write access to the output directory; output directory deleted or never created before bundling; disk full during license extraction; destination path exists as a directory named LICENSE.","solutions":["Ensure outputDir exists and is writable (mkdir -p and check permissions / run with correct user)","Check the destination license path is not a directory and no permission conflicts exist","Free disk space if ENOSPC is reported","Rerun the bundler; inspect the wrapped error for the root cause"],"exampleFix":"// before\nif err := extractCLILicense(tarballPath, outputDir); err != nil { return err }\n// after\nif err := os.MkdirAll(outputDir, 0o755); err != nil { return fmt.Errorf(\"output dir: %w\", err) }\nif err := extractCLILicense(tarballPath, outputDir); err != nil { return err }","handlingStrategy":"try-catch","validationCode":"if info, err := os.Stat(outputDir); err != nil || !info.IsDir() { os.MkdirAll(outputDir, 0o755) }\nif info, err := os.Stat(outputDir); err != nil || !info.IsDir() || unix.Access(outputDir, unix.W_OK) != nil { return fmt.Errorf(\"output dir not writable: %s\", outputDir) }","typeGuard":"func dirWritable(dir string) bool { p := filepath.Join(dir, \".probe\"); if err := os.WriteFile(p, nil, 0o644); err != nil { return false }; os.Remove(p); return true }","tryCatchPattern":"if err := extractCLILicense(tarballPath, outputDir); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) { log.Printf(\"license write failed at %s: %v\", pe.Path, pe.Err) }\n    return fmt.Errorf(\"license extraction failed: %w\", err)\n}","preventionTips":["Always create and verify the output directory before bundling","Run the bundler as a user with write access to the output path","Monitor disk space before large bundle operations","Avoid destination names that collide with directories"],"tags":["go","tarball","file-write","license-extraction"],"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"}