moonD4rk/HackBrowserData · error

close

Error message

close %s: %w

What it means

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.

Solutions

  1. Check free disk space on the output volume and retry with adequate space.
  2. Write to a local disk instead of a network/removable drive.
  3. Exclude the output directory from AV/sync tools that may hold or interfere with the handle.
  4. Treat the written file as unreliable: delete and regenerate after fixing the environment.

Example fix

// before: ignoring close errors leaves truncated files
f.Close()
// after
if cerr := f.Close(); cerr != nil && err == nil {
	err = fmt.Errorf("close %s: %w", filename, cerr)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// before writing, ensure adequate space:
if st, err := diskUsage(outputDir); err == nil && st.Free < minRequired { return errors.New("insufficient disk space") }

Try / catch

if err := w.Write(); err != nil {
	if strings.Contains(err.Error(), "close ") {
		// output unreliable: delete partial files and retry after freeing space
	}
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of moonD4rk/HackBrowserData@0503d04d7a (2026-09-06). Data as JSON: /api/errors/da539e6068cd8dca. Report an issue: GitHub.

Appendix: source

Thrown at output/output.go:154

	// cookie-editor skipping non-cookie data), don't create the file.
	var buf bytes.Buffer
	if err := o.formatter.format(&buf, rows); err != nil {
		return fmt.Errorf("format %s: %w", category, err)
	}
	if buf.Len() == 0 {
		return nil
	}

	filename := fmt.Sprintf("%s.%s", category, o.formatter.ext())
	path := filepath.Join(o.dir, filename)

	f, err := os.OpenFile(filepath.Clean(path), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600)
	if err != nil {
		return fmt.Errorf("create %s: %w", filename, err)
	}
	defer func() {
		if cerr := f.Close(); cerr != nil && err == nil {
			err = fmt.Errorf("close %s: %w", filename, cerr)
		}
	}()

	if strings.HasSuffix(path, ".csv") {
		if _, err := f.Write(utf8BOM); err != nil {
			return fmt.Errorf("write BOM: %w", err)
		}
	}

	if _, err := f.Write(buf.Bytes()); err != nil {
		return fmt.Errorf("write %s: %w", filename, err)
	}
	return nil
}

View on GitHub (pinned to 0503d04d7a)