{"record":{"id":"da539e6068cd8dca","repo":"moonD4rk/HackBrowserData","slug":"close-s-w","errorCode":null,"errorMessage":"close %s: %w","messagePattern":"close (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"output/output.go","lineNumber":154,"sourceCode":"\t// cookie-editor skipping non-cookie data), don't create the file.\n\tvar buf bytes.Buffer\n\tif err := o.formatter.format(&buf, rows); err != nil {\n\t\treturn fmt.Errorf(\"format %s: %w\", category, err)\n\t}\n\tif buf.Len() == 0 {\n\t\treturn nil\n\t}\n\n\tfilename := fmt.Sprintf(\"%s.%s\", category, o.formatter.ext())\n\tpath := filepath.Join(o.dir, filename)\n\n\tf, err := os.OpenFile(filepath.Clean(path), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"create %s: %w\", filename, err)\n\t}\n\tdefer func() {\n\t\tif cerr := f.Close(); cerr != nil && err == nil {\n\t\t\terr = fmt.Errorf(\"close %s: %w\", filename, cerr)\n\t\t}\n\t}()\n\n\tif strings.HasSuffix(path, \".csv\") {\n\t\tif _, err := f.Write(utf8BOM); err != nil {\n\t\t\treturn fmt.Errorf(\"write BOM: %w\", err)\n\t\t}\n\t}\n\n\tif _, err := f.Write(buf.Bytes()); err != nil {\n\t\treturn fmt.Errorf(\"write %s: %w\", filename, err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":136,"sourceCodeEnd":169,"githubUrl":"https://github.com/moonD4rk/HackBrowserData/blob/0503d04d7a8d0379d060268a74f1b149e5a0aad5/output/output.go#L136-L169","documentation":"writeFile registers a deferred f.Close() and promotes its error (only if no earlier error occurred) via fmt.Errorf(\"close %s: %w\", ...). This reports that closing the output file failed, typically meaning buffered data was never flushed to disk and the result file may be empty or incomplete.","triggerScenarios":"The deferred f.Close() returned a non-nil error: disk became full (close flushes OS buffers), the file handle was invalidated (filesystem unmounted, network drive dropped), or on Windows an underlying lock/error surfaced at close time.","commonSituations":"Disk filling up mid-write so Close cannot flush; writing to a network share or removable drive that disconnects; file watched/locked by AV or sync clients (OneDrive/Dropbox) interfering at close.","solutions":["Check free disk space on the output volume and retry with adequate space.","Write to a local disk instead of a network/removable drive.","Exclude the output directory from AV/sync tools that may hold or interfere with the handle.","Treat the written file as unreliable: delete and regenerate after fixing the environment."],"exampleFix":"// before: ignoring close errors leaves truncated files\nf.Close()\n// after\nif cerr := f.Close(); cerr != nil && err == nil {\n\terr = fmt.Errorf(\"close %s: %w\", filename, cerr)\n}","handlingStrategy":"try-catch","validationCode":"// before writing, ensure adequate space:\nif st, err := diskUsage(outputDir); err == nil && st.Free < minRequired { return errors.New(\"insufficient disk space\") }","typeGuard":null,"tryCatchPattern":"if err := w.Write(); err != nil {\n\tif strings.Contains(err.Error(), \"close \") {\n\t\t// output unreliable: delete partial files and retry after freeing space\n\t}\n}","preventionTips":["Ensure ample free disk space before extraction runs.","Prefer local disks over network/USB targets.","Exclude output dirs from sync clients that lock handles.","Treat any close error as file corruption — regenerate the file."],"tags":["filesystem","file-close","disk","output"],"backgroundTag":"file-write-failed","analyzedSha":"0503d04d7a8d0379d060268a74f1b149e5a0aad5","analyzedAt":"2026-09-06T13:38:28.707Z","contentChangedAt":"2026-09-06T13:38:28.707Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}