{"record":{"id":"80f5fb482b8033ad","repo":"ipfs/kubo","slug":"creating-output-file-q-w","errorCode":null,"errorMessage":"creating output file %q: %w","messagePattern":"creating output file %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"profile/profile.go","lineNumber":190,"sourceCode":"\t\t\t}\n\t\t\tselect {\n\t\t\tcase results <- profileResult{buf: &b, fName: fName}:\n\t\t\tcase <-ctx.Done():\n\t\t\t}\n\t\t}(c)\n\t}\n\tgo func() {\n\t\twg.Wait()\n\t\tclose(results)\n\t}()\n\n\tfor res := range results {\n\t\tif res.err != nil {\n\t\t\treturn res.err\n\t\t}\n\t\tout, err := p.archive.Create(res.fName)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"creating output file %q: %w\", res.fName, err)\n\t\t}\n\t\t_, err = io.Copy(out, res.buf)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"compressing result %q: %w\", res.fName, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc goroutineStacksText(ctx context.Context, _ Options, w io.Writer) error {\n\treturn WriteAllGoroutineStacks(w)\n}\n\nfunc goroutineStacksProto(ctx context.Context, _ Options, w io.Writer) error {\n\treturn pprof.Lookup(\"goroutine\").WriteTo(w, 0)\n}\n","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/profile/profile.go#L172-L208","documentation":"runProfile consumes collected profile results and adds each one to the output archive via p.archive.Create(res.fName). This error means the archive writer refused to create the named entry for a profile. It is wrapped with the entry name so the developer knows which profile entry failed; the root cause is on the archive/underlying writer side, not profile collection.","triggerScenarios":"p.archive.Create(fName) returns an error: the underlying archive writer was already closed or corrupted, the backing output file became unwritable mid-run, the archive implementation rejects the fName (invalid/duplicate entry name), or the underlying io.Writer to disk failed.","commonSituations":"Writing a diagnostics archive to a full disk or read-only mount; closing the archive writer before runProfile finishes draining the results channel; custom archive implementations that reject entry names.","solutions":["Inspect the wrapped error from archive.Create — it names the underlying cause (closed writer, path, permission)","Keep the archive open until runProfile has fully drained the results channel (do not close it concurrently or early)","Verify the output destination (file/mount) is writable and has free space","Check fName for characters the archive format disallows"],"exampleFix":"// before\narchive, _ := archiveBuilder(p.outputFile)\narchive.Close() // closed too early\nerr := WriteProfiles(ctx, p) // Create fails: writer closed\n// after\narchive, _ := archiveBuilder(p.outputFile)\nerr := WriteProfiles(ctx, p)\narchive.Close() // close only after profiles are written","handlingStrategy":"try-catch","validationCode":"f, err := os.OpenFile(dest, os.O_CREATE|os.O_WRONLY, 0o644)\nif err != nil {\n    return fmt.Errorf(\"archive destination unwritable: %w\", err)\n}\nf.Close()","typeGuard":null,"tryCatchPattern":"err := WriteProfiles(ctx, p)\nif err != nil {\n    if strings.HasPrefix(err.Error(), \"creating output file\") {\n        log.Printf(\"archive entry creation failed, check archive lifetime/disk: %v\", errors.Unwrap(err))\n    }\n    return err\n}","preventionTips":["Never close the archive writer before runProfile drains the results channel","Verify the output path is on a writable, non-full filesystem before starting","Use standard archive entry names (no path separators or duplicate names)","Let WriteProfiles own the archive lifecycle end-to-end"],"tags":["io","archive","diagnostics"],"backgroundTag":"archive-entry-create-failed","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"}