{"record":{"id":"244590721ed76b6c","repo":"Hmbown/CodeWhale","slug":"codewhale-runtime-event-file-is-empty","errorCode":null,"errorMessage":"Codewhale runtime event file is empty.","messagePattern":"Codewhale runtime event file is empty\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/tui/pet_watch/pet-native.js","lineNumber":2512,"sourceCode":"            privacy: 'redact',\n            warnings: [...new Set(warnings)],\n            metadata: {\n                sourceFormat: 'codewhale.runtime-events/v2',\n                timeBasis: 'wall-clock',\n                sourceFilename: filename,\n                threadId,\n                model,\n                skippedDeltas,\n                recordCount: this.recordCount,\n                timeUnit: 'ms',\n            },\n        };\n    }\n}\nexports.CodewhaleRuntimeTrace = CodewhaleRuntimeTrace;\nfunction fromCodewhaleRuntime(records, filename = 'Codewhale runtime', maxEvents = 250_000) {\n    if (!records.length)\n        throw new Error('Codewhale runtime event file is empty.');\n    const trace = new CodewhaleRuntimeTrace(filename, maxEvents);\n    trace.append(records);\n    return trace.snapshot();\n}\n/** The journal owns request state until a matching terminal receipt. A live\n * driver may confirm that state only while its cursor-checked stream is healthy.\n * Ordinary open tool spans remain unknown-duration; no execution is inferred. */\nfunction observeRuntimeRequests(trace, observedThrough) {\n    const origin = Date.parse(trace.originTime ?? '');\n    if (trace.metadata.sourceFormat !== 'codewhale.runtime-events/v2' || !Number.isFinite(origin)\n        || !Number.isFinite(observedThrough))\n        throw new Error('Invalid Runtime observation horizon.');\n    const at = observedThrough - origin;\n    const events = trace.events.map(e => e.openEnded && e.attributes['whalesong.waiting'] === true && at >= e.startTime\n        ? { ...e, endTime: at, openEnded: false } : e);\n    return { ...trace, events, duration: Math.max(trace.duration, at) };\n}\n","sourceCodeStart":2494,"sourceCodeEnd":2530,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tui/pet_watch/pet-native.js#L2494-L2530","documentation":"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.","triggerScenarios":"Calling `fromCodewhaleRuntime([])`, or passing the parsed contents of a zero-byte / empty runtime event file to the trace loader.","commonSituations":"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.","solutions":["Check the runtime event file is non-empty before loading (file size > 0 / parsed array length > 0).","Re-capture the runtime events — an empty file means nothing was recorded.","Fix the read/filter step that produced an empty records array (wrong path, over-aggressive filter, no JSONL lines).","Guard the call: skip loading empty files and surface a user-facing 'no events recorded' message instead."],"exampleFix":"// before\nconst trace = fromCodewhaleRuntime(readRecords(path));\n// after\nconst records = readRecords(path);\nif (records.length === 0) {\n  console.warn(`no runtime events in ${path}; skipping`);\n} else {\n  const trace = fromCodewhaleRuntime(records);\n}","handlingStrategy":"validation","validationCode":"const records = readRuntimeRecords(path);\nif (!Array.isArray(records) || records.length === 0) {\n  console.warn(`skipping empty runtime event file: ${path}`);\n  return null;\n}","typeGuard":"function isNonEmptyRecords(v) {\n  return Array.isArray(v) && v.length > 0;\n}","tryCatchPattern":"try {\n  const trace = fromCodewhaleRuntime(records);\n} catch (e) {\n  if (e.message === 'Codewhale runtime event file is empty.') {\n    return null; // nothing recorded; treat as no-trace\n  }\n  throw e;\n}","preventionTips":["Check file size / parsed length before loading.","Treat empty event files as 'nothing recorded', not a loadable trace.","Ensure the writer flushes records before the process exits.","Glob for captures with a min-size or line-count filter."],"tags":["trace-import","empty-input","runtime-events"],"backgroundTag":"empty-result-set","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}