cockroachdb/cockroach · error

error while processing file %s

Error message

error while processing file %s

What it means

In `cockroach debug merge-logs`, finding the start offset binary-searches each file (sort.Search) for the first entry with Time >= from. Inside that predicate, log.NewEntryDecoderWithFormat(f, editMode, format) failure panics with 'error while processing file <name>'; the deferred recover() converts the panic into the function's returned error, so the command fails with this message naming the file.

Source

Thrown at pkg/cli/debug_merge_logs.go:591

	}
	fi, err := f.Stat()
	if err != nil {
		return err
	}
	size := fi.Size()
	defer func() {
		if r := recover(); r != nil {
			err = r.(error)
		}
	}()
	offset := sort.Search(int(size), func(i int) bool {
		if _, err := f.Seek(int64(i), io.SeekStart); err != nil {
			panic(err)
		}
		var e logpb.Entry
		d, err := log.NewEntryDecoderWithFormat(f, editMode, format)
		if err != nil {
			panic(errors.WithMessagef(err, "error while processing file %s", f.Name()))
		}
		if err := d.Decode(&e); err != nil {
			if err == io.EOF {
				return true
			}
			panic(errors.WithMessagef(err, "error while processing file %s", f.Name()))
		}
		return e.Time >= from.UnixNano()
	})
	if _, err := f.Seek(int64(offset), io.SeekStart); err != nil {
		return err
	}
	var e logpb.Entry
	d, err := log.NewEntryDecoderWithFormat(f, editMode, format)
	if err != nil {
		return err
	}
	if err := d.Decode(&e); err != nil {

View on GitHub (pinned to 8812064a01)

Solutions

  1. Drop the --format flag and let the command auto-detect each file's format
  2. Verify the file is a cockroach log produced by a compatible version (try decoding it standalone with merge-logs on just that file)
  3. Separate inputs by format and run once per group instead of merging mixed encodings
  4. Decompress .gz files first if they are being passed compressed

Example fix

# before
cockroach debug merge-logs --format=json node1.log node2.log

# after (auto-detect per file)
cockroach debug merge-logs node1.log node2.log
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Passing an explicit --format that this binary cannot construct a decoder for (unsupported/unknown format enum), or a file that cannot be decoded under the requested edit mode — the construction happens at arbitrary offsets during the binary search, so a mismatched --format flag fails fast here.

Common situations: Running merge-logs with --format=json over files written in the default text format (or vice versa); using --redactable expectations on files that don't match; logs from a much newer version with a changed encoding.

Related errors


AI-assisted analysis of cockroachdb/cockroach@8812064a01 (2026-08-15). Data as JSON: /api/errors/b8fa0c931936259b. Report an issue: GitHub.