Hmbown/CodeWhale · error · Error

Codewhale runtime event file is empty.

Error message

Codewhale runtime event file is empty.

What it means

Thrown by `fromCodewhaleRuntime` in pet-native.js when the records array passed in is empty (`records.length === 0`). The library treats an empty event file as unusable input rather than returning an empty trace, so callers get a loud failure instead of a blank timeline.

Solutions

  1. Check the runtime event file is non-empty before loading (file size > 0 / parsed array length > 0).
  2. Re-capture the runtime events — an empty file means nothing was recorded.
  3. Fix the read/filter step that produced an empty records array (wrong path, over-aggressive filter, no JSONL lines).
  4. Guard the call: skip loading empty files and surface a user-facing 'no events recorded' message instead.

Example fix

// before
const trace = fromCodewhaleRuntime(readRecords(path));
// after
const records = readRecords(path);
if (records.length === 0) {
  console.warn(`no runtime events in ${path}; skipping`);
} else {
  const trace = fromCodewhaleRuntime(records);
}
Defensive patterns

Strategy: validation

Validate before calling

const records = readRuntimeRecords(path);
if (!Array.isArray(records) || records.length === 0) {
  console.warn(`skipping empty runtime event file: ${path}`);
  return null;
}

Type guard

function isNonEmptyRecords(v) {
  return Array.isArray(v) && v.length > 0;
}

Try / catch

try {
  const trace = fromCodewhaleRuntime(records);
} catch (e) {
  if (e.message === 'Codewhale runtime event file is empty.') {
    return null; // nothing recorded; treat as no-trace
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling `fromCodewhaleRuntime([])`, or passing the parsed contents of a zero-byte / empty runtime event file to the trace loader.

Common situations: A runtime events file was created but never written to (crash before flush); a glob matched an empty log; a filter or read step produced an empty array before handing records to the importer.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/244590721ed76b6c. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/tui/pet_watch/pet-native.js:2512

            privacy: 'redact',
            warnings: [...new Set(warnings)],
            metadata: {
                sourceFormat: 'codewhale.runtime-events/v2',
                timeBasis: 'wall-clock',
                sourceFilename: filename,
                threadId,
                model,
                skippedDeltas,
                recordCount: this.recordCount,
                timeUnit: 'ms',
            },
        };
    }
}
exports.CodewhaleRuntimeTrace = CodewhaleRuntimeTrace;
function fromCodewhaleRuntime(records, filename = 'Codewhale runtime', maxEvents = 250_000) {
    if (!records.length)
        throw new Error('Codewhale runtime event file is empty.');
    const trace = new CodewhaleRuntimeTrace(filename, maxEvents);
    trace.append(records);
    return trace.snapshot();
}
/** The journal owns request state until a matching terminal receipt. A live
 * driver may confirm that state only while its cursor-checked stream is healthy.
 * Ordinary open tool spans remain unknown-duration; no execution is inferred. */
function observeRuntimeRequests(trace, observedThrough) {
    const origin = Date.parse(trace.originTime ?? '');
    if (trace.metadata.sourceFormat !== 'codewhale.runtime-events/v2' || !Number.isFinite(origin)
        || !Number.isFinite(observedThrough))
        throw new Error('Invalid Runtime observation horizon.');
    const at = observedThrough - origin;
    const events = trace.events.map(e => e.openEnded && e.attributes['whalesong.waiting'] === true && at >= e.startTime
        ? { ...e, endTime: at, openEnded: false } : e);
    return { ...trace, events, duration: Math.max(trace.duration, at) };
}

View on GitHub (pinned to 73e0f67d83)