{"record":{"id":"708092c893eb5101","repo":"Hmbown/CodeWhale","slug":"invalid-event-v1-pet-input-import-through-importtrace-first-708092","errorCode":null,"errorMessage":"Invalid event-v1 pet input. Import through importTrace first.","messagePattern":"Invalid event-v1 pet input\\. Import through importTrace first\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/ios/Resources/pet-native.js","lineNumber":1183,"sourceCode":" * 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\n            : { ...e.attributes, 'whalesong.error_onset_ms': (0, model_js_1.errorOnsetOf)(e) - originMs } }))\n        .sort((a, b) => a.startTime - b.startTime || order(a.id, b.id));\n    let lastOnset = 0;\n    for (const e of events) {\n        durationMs = Math.max(durationMs, e.endTime);\n        lastOnset = Math.max(lastOnset, e.startTime);\n    }\n    const failures = events.filter(e => e.category === 'error' || e.status === 'error').map(model_js_1.errorOnsetOf).sort((a, b) => a - b);","sourceCodeStart":1165,"sourceCodeEnd":1201,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/ios/Resources/pet-native.js#L1165-L1201","documentation":"The pet ingestor requires events already validated as event-v1 schema (schemaVersion 1, non-empty id/traceId, known category, finite non-negative startTime <= endTime, present attributes). Raw or malformed event objects are rejected with this message, telling you to run them through importTrace first. This keeps replay determinism by guaranteeing a uniform event shape.","triggerScenarios":"Passing events that were constructed by hand or parsed from a foreign trace format directly into the pet builder instead of the importTrace pipeline; also any single field missing (attributes omitted, schemaVersion missing/2, negative startTime, endTime before startTime).","commonSituations":"Mixing raw OTel spans or custom log records into a pet call, skipping the normal import flow, or working with an older trace export produced before the event-v1 schema.","solutions":["Route your events through importTrace to normalize them into event-v1 objects before building a pet.","Check each event: schemaVersion === 1, id, traceId, category in CATEGORIES, finite startTime/endTime with startTime >= 0 and endTime >= startTime, and a non-null attributes object.","Re-export your trace with a current exporter if it predates event-v1."],"exampleFix":"// before\nbuildPet(rawSpans);\n// after\nconst events = importTrace(rawSpans);\nbuildPet(events, { originMs: 0 });","handlingStrategy":"validation","validationCode":"const ok = events.every(e => e.schemaVersion === 1 && e.id && e.traceId\n  && CATEGORIES.includes(e.category)\n  && Number.isFinite(e.startTime) && Number.isFinite(e.endTime)\n  && e.startTime >= 0 && e.endTime >= e.startTime && e.attributes);\nif (!ok) events = importTrace(rawEvents);","typeGuard":"const isEventV1 = (e) => !!e && e.schemaVersion === 1 && typeof e.id === 'string' && typeof e.traceId === 'string' && typeof e.attributes === 'object';","tryCatchPattern":"try { buildPet(events) } catch (err) { if (err.message.includes('event-v1')) events = importTrace(events); else throw err; }","preventionTips":["Never bypass importTrace for pet inputs","Pin exporters to the event-v1 schema","Add a CI check validating trace exports against event-v1"],"tags":["schema","validation","trace"],"backgroundTag":"schema-validation-failed","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}