{"record":{"id":"508cb12551a52ba5","repo":"ipfs/kubo","slug":"error-creating-output-file-s-w","errorCode":null,"errorMessage":"error creating output file '%s': %w","messagePattern":"error creating output file '(.+?)': %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"repo/fsrepo/migrations/unpack.go","lineNumber":99,"sourceCode":"\t\t\t\treturn fmt.Errorf(\"error extracting binary from archive: %w\", err)\n\t\t\t}\n\n\t\t\tbin = rc\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif bin == nil {\n\t\treturn errors.New(\"no binary found in archive\")\n\t}\n\n\treturn writeToPath(bin, out)\n}\n\nfunc writeToPath(rc io.Reader, out string) error {\n\tbinfi, err := os.Create(out)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error creating output file '%s': %w\", out, err)\n\t}\n\tdefer binfi.Close()\n\n\t_, err = io.Copy(binfi, rc)\n\n\treturn err\n}\n","sourceCodeStart":81,"sourceCodeEnd":107,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/repo/fsrepo/migrations/unpack.go#L81-L107","documentation":"writeToPath opens (or creates) the output file with os.Create to receive the extracted migration binary. If the file cannot be created — because of permissions, a missing parent directory, or a path conflict with a directory — the underlying OS error is wrapped with the output path and returned. The wrapped cause identifies the exact OS-level reason.","triggerScenarios":"Calling unpackArchive/unpackTgz/unpackZip where the `out` path is unwritable: parent directory does not exist, the path is a directory, the process lacks write permission, the disk is full, or out is read-only (e.g. installing into /usr/local/bin without root).","commonSituations":"Running ipfs-update without elevated privileges when writing to a system bin dir, IPFS_PATH pointing at a directory deleted or recreated with different ownership, read-only container filesystems, or disk exhaustion on small VPSes.","solutions":["Ensure the parent directory of the output path exists (os.MkdirAll) before unpacking.","Check and fix permissions on the target path: chmod/chown or choose a writable directory.","If writing to a system path, re-run with elevated privileges or install to a user-writable location on PATH.","Inspect the wrapped %w cause (e.g. EACCES, ENOSPC) and address the underlying OS condition (free disk, remount rw)."],"exampleFix":"// before\nerr := migrations.Unpack(archivePath, out)\n// after: make sure the destination dir exists first\nif err := os.MkdirAll(filepath.Dir(out), 0o755); err != nil {\n\treturn err\n}\nerr := migrations.Unpack(archivePath, out)","handlingStrategy":"validation","validationCode":"dir := filepath.Dir(out)\nif err := os.MkdirAll(dir, 0o755); err != nil { return err }\nif info, err := os.Stat(out); err == nil && info.IsDir() {\n\treturn fmt.Errorf(\"%s is a directory\", out)\n}\ntest, err := os.OpenFile(out, os.O_CREATE|os.O_WRONLY, 0o755)\nif err != nil { return err }\ntest.Close()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always MkdirAll the parent directory before writing outputs.","Choose install targets on PATH that the current user can write.","Check free disk space before extracting binaries.","Unwrap the %w cause with errors.As(*fs.PathError) to distinguish EACCES vs ENOSPC."],"tags":["filesystem","permissions","io"],"backgroundTag":"file-create-permission-denied","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}