moonD4rk/HackBrowserData · error

create %s: %w

Error message

create %s: %w

What it means

After formatting succeeds, writeFile opens the destination file (category.ext) inside the output dir with O_CREATE|O_WRONLY|O_TRUNC and mode 0600. This error wraps os.OpenFile failure, meaning the result file could not be created or truncated in the output directory.

Source

Thrown at output/output.go:150

}

func (o *Writer) writeFile(category string, rows []row) (err error) {
	// Format to buffer first — if formatter produces no output (e.g.
	// 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)

Solutions

  1. Check permissions and ownership of the output directory; pick a different dir if restricted.
  2. Close any program holding the target file open (Excel/editors lock CSVs on Windows).
  3. Rename output dir/file if it collides with Windows reserved names or path-length limits; use a shorter output dir.
  4. Exclude/whitelist the output directory in security software if it blocks file creation.
  5. Check ulimit -n (too many open files) if running in a long-lived process.

Example fix

// before
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600)
// after: surface a clearer failure and retry once in temp dir
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600)
if err != nil {
	tmp, terr := os.CreateTemp("", category+"-*."+ext)
	if terr != nil { return fmt.Errorf("create %s: %w", filename, err) }
	f = tmp
}
Defensive patterns

Strategy: validation

Validate before calling

if err := unix.Access(dir, unix.W_OK); err != nil { return fmt.Errorf("dir not writable: %v", err) } // or attempt a probe file
dummy := filepath.Join(dir, ".write-test")
if err := os.WriteFile(dummy, nil, 0o600); err != nil { return err }
os.Remove(dummy)

Type guard

func canCreateIn(dir string) bool {
	f, err := os.CreateTemp(dir, ".probe-*")
	if err != nil { return false }
	f.Close(); os.Remove(f.Name())
	return true
}

Try / catch

if err := w.Write(); err != nil {
	var pe *fs.PathError
	if errors.As(err, &pe) && errors.Is(err, fs.ErrPermission) {
		// pick another output dir or elevate
	}
}

Prevention

When it happens

Trigger: os.OpenFile(filepath.Clean(path), ...) failed: permission denied in o.dir, the path exists as a directory, disk full, too many open files, or filename invalid for the platform (reserved names like 'con.csv' on Windows, over-long paths).

Common situations: Output directory became read-only after creation; antivirus/EDR blocking creation of files like password.csv; Windows reserved device names; category name containing path-hostile characters; file locked by another process (e.g. an editor or spreadsheet holding the CSV open).

Understand the failure class

Background: "Permission denied" / "Failed to write" file errors: why a library can't write its files to disk (EACCES, EPERM, ENOSPC) and how to fix them — this error's family across 43 libraries.

Related errors


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