{"record":{"id":"ec081c2827fbde7f","repo":"Hmbown/CodeWhale","slug":"invalid-pet-clock-origin-native","errorCode":null,"errorMessage":"Invalid pet clock origin.","messagePattern":"Invalid pet clock origin\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/ios/Resources/pet-native.js","lineNumber":1175,"sourceCode":"    }\n}\nexports.PetLiveTape = PetLiveTape;\nconst order = (a, b) => a < b ? -1 : a > b ? 1 : 0;\nconst keyOf = (e) => JSON.stringify([e.traceId, e.id]);\nconst isContainer = (e) => e.attributes['whalesong.container'] === true\n    || e.attributes['codewhale.container'] === true;\n/** Compile a single trace. Unknown-duration spans provide onsets, not occupancy.\n * Updates of the same trace/id replace earlier snapshots rather than double count.\n * An endpoint onset gets its own bucket; intervals use [start, end). */\nfunction compilePetTelemetry(input, durationMs = 0, firstSequence = 0, originMs = 0) {\n    if (input.length > 250_000)\n        throw new Error('Pet input exceeds 250000 events.');\n    if (!Number.isFinite(durationMs) || durationMs < 0)\n        throw new Error('Invalid pet duration.');\n    if (!Number.isSafeInteger(firstSequence) || firstSequence < 0)\n        throw new Error('Invalid first pet bucket.');\n    if (!Number.isFinite(originMs))\n        throw new Error('Invalid pet clock origin.');\n    durationMs = Math.max(0, durationMs - originMs);\n    const unique = new Map();\n    const traces = new Set();\n    for (const e of input) {\n        if (e.schemaVersion !== 1 || !e.id || !e.traceId || !model_js_1.CATEGORIES.includes(e.category)\n            || !Number.isFinite(e.startTime) || !Number.isFinite(e.endTime)\n            || e.startTime < 0 || e.endTime < e.startTime || !e.attributes)\n            throw new Error('Invalid event-v1 pet input. Import through importTrace first.');\n        traces.add(e.traceId);\n        unique.set(keyOf(e), e);\n    }\n    if (traces.size > 1)\n        throw new Error('Select one trace for the pet.');\n    const parents = new Set([...unique.values()].filter(e => e.parentId).map(e => e.parentId));\n    const events = [...unique.values()].filter(e => !isContainer(e)\n        && !(e.category === 'orchestration' && parents.has(e.id)))\n        .map(e => ({ ...e, startTime: e.startTime - originMs, endTime: (e.openEnded ? e.startTime : e.endTime) - originMs,\n        attributes: e.attributes['whalesong.error_onset_ms'] === undefined ? e.attributes","sourceCodeStart":1157,"sourceCodeEnd":1193,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/ios/Resources/pet-native.js#L1157-L1193","documentation":"The pet replay ingestor in pet-native.js validates a numeric clock origin via Number.isFinite(originMs) before replaying events. This error means the originMs argument passed to the pet build/score entry point is not a finite number (NaN, Infinity, undefined, string, etc.). The library throws early so bin math (durations and timestamps shifted by originMs) stays well-defined.","triggerScenarios":"Calling the pet replay/builder function with an originMs argument that is NaN, Infinity, null, or a non-numeric value (e.g. a Date object not converted with .getTime(), or an undefined variable).","commonSituations":"Developers passing Date objects or ISO strings instead of epoch milliseconds, reading the origin from an unpopulated config field, or JSON round-trips that turned a number into null.","solutions":["Pass a finite epoch-milliseconds number as originMs, e.g. Date.parse(traceStart) for a date string.","Check the value with Number.isFinite(originMs) at the call site before invoking the API.","If the origin comes from config or metadata, verify it is present and numeric; fall back to 0 for a zero-based trace."],"exampleFix":"// before\nbuildPet(trace, { originMs: trace.startTimeISO });\n// after\nbuildPet(trace, { originMs: Date.parse(trace.startTimeISO) });","handlingStrategy":"validation","validationCode":"if (!Number.isFinite(originMs)) throw new TypeError('originMs must be a finite number');\nconst origin = typeof origin === 'string' ? Date.parse(origin) : origin;","typeGuard":"const isFiniteNumber = (v) => typeof v === 'number' && Number.isFinite(v);","tryCatchPattern":null,"preventionTips":["Always convert dates with Date.parse() or Date.getTime() before passing an origin","Default originMs to 0 when absent","Keep trace timestamps relative, not absolute epoch values"],"tags":["validation","numeric-input"],"backgroundTag":"invalid-argument-value","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-22T16:17:23.217Z"}