{"record":{"id":"619cae32fe35ced5","repo":"wagoodman/dive","slug":"cannot-write-to-export-file-w","errorCode":null,"errorMessage":"cannot write to export file: %w","messagePattern":"cannot write to export file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/dive/cli/internal/command/adapter/exporter.go","lineNumber":60,"sourceCode":"\t})\n\n\tbytes, err := export.NewExport(analysis).Marshal()\n\tif err != nil {\n\t\tmon.SetError(err)\n\t\treturn fmt.Errorf(\"cannot marshal export payload: %w\", err)\n\t} else {\n\t\tmon.SetCompleted()\n\t}\n\n\tfile, err := e.filesystem.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot open export file: %w\", err)\n\t}\n\tdefer file.Close()\n\n\t_, err = file.Write(bytes)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot write to export file: %w\", err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":42,"sourceCodeEnd":64,"githubUrl":"https://github.com/wagoodman/dive/blob/d6c691947f8fda635c952a17ee3b7555379d58f0/cmd/dive/cli/internal/command/adapter/exporter.go#L42-L64","documentation":"Returned when writing the already-marshalled JSON bytes to the opened export file fails. The file was successfully created, but the actual Write call errored — typically disk full (ENOSPC), quota exceeded, or the file descriptor invalidated by an external actor. Note the file is opened without O_TRUNC, so pre-existing longer content can also leave stale trailing bytes on success.","triggerScenarios":"dive --json <path> where the disk fills during the write, a filesystem quota is hit, the filesystem is read-only remounted between open and write, or an antivirus/container runtime holds/invalidates the fd.","commonSituations":"CI runners with small ephemeral disks writing large image exports; exporting into a full volume mount; overlay filesystems in containers hitting disk pressure.","solutions":["Check the wrapped error — 'no space left on device' means freeing disk or pointing --json elsewhere","Verify the target filesystem is writable and not quota-capped (df -h <dir>)","Re-run the export once space is freed; the payload is rebuilt from the in-memory analysis so a retry is safe","Operators of the exporter can add O_TRUNC to the OpenFile flags to avoid stale trailing bytes from previous longer files"],"exampleFix":"// before\nfile, err := e.filesystem.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)\n\n// after (also truncate stale content)\nfile, err := e.filesystem.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)","handlingStrategy":"retry","validationCode":"// check free space before writing large exports\nvar stat syscall.Statfs_t\nif err := syscall.Statfs(filepath.Dir(path), &stat); err == nil {\n    free := stat.Bavail * uint64(stat.Bsize)\n    if free < uint64(len(payloadEstimate)) { return fmt.Errorf(\"insufficient space for export\") }\n}","typeGuard":null,"tryCatchPattern":"err := exporter.ExportTo(ctx, analysis, path)\nif err != nil && strings.Contains(err.Error(), \"cannot write to export file\") {\n    // transient ENOSPC/EIO: free space or change path, then retry once\n    err = exporter.ExportTo(ctx, analysis, altPath)\n}\nif err != nil { return err }","preventionTips":["Monitor disk space on CI runners that export large JSON payloads","Write exports to a dedicated artifacts volume with quota headroom","Retry with an alternate path when the write target is unreliable"],"tags":["export","io","disk-full","filesystem","json"],"backgroundTag":null,"analyzedSha":"d6c691947f8fda635c952a17ee3b7555379d58f0","analyzedAt":"2026-08-15T09:42:35.293Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}