{"record":{"id":"607d478a00e134e9","repo":"Hmbown/CodeWhale","slug":"record-index-1-invalid-status","errorCode":null,"errorMessage":"Record ${index + 1}: invalid status.","messagePattern":"Record (.+?): invalid status\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/src/core/ingest.ts","lineNumber":133,"sourceCode":"  if (typeof v === 'number' && !Number.isSafeInteger(v)) throw new Error(`${field} lost precision: encode OTLP nanoseconds as a decimal string.`);\n  const s = String(v ?? '');\n  if (!/^\\d{1,20}$/.test(s) || BigInt(s) > 18446744073709551615n) throw new Error(`Invalid ${field}: expected an OTLP nanosecond integer string.`);\n  return BigInt(s);\n}\nfunction otelStatus(v: unknown): Status {\n  const c = obj(v).code;\n  return c === 2 || c === 'STATUS_CODE_ERROR' ? 'error' : c === 1 || c === 'STATUS_CODE_OK' ? 'success' : 'unknown';\n}\nfunction normalizedEvent(v: unknown, index: number): WhaleEvent {\n  const a = obj(v), id = str(a.id), traceId = str(a.traceId), name = str(a.name);\n  if (!id || !traceId || !name) throw new Error(`Record ${index + 1} requires nonempty id, traceId, and name.`);\n  if (a.schemaVersion !== undefined && a.schemaVersion !== 1) throw new Error(`Record ${index + 1}: unsupported schemaVersion ${a.schemaVersion}.`);\n  const startTime = number(a.startTime, 'startTime', false)!;\n  const endTime = number(a.endTime, 'endTime') ?? startTime;\n  if (endTime < startTime) throw new Error(`Record ${index + 1}: endTime precedes startTime.`);\n  if (a.category !== undefined && !CATEGORIES.includes(a.category)) throw new Error(`Unknown category \"${a.category}\". Use \"other\" plus subtype for extensions.`);\n  const allowed: Status[] = ['pending', 'running', 'success', 'error', 'unknown'];\n  if (a.status !== undefined && !allowed.includes(a.status)) throw new Error(`Record ${index + 1}: invalid status.`);\n  const at = obj(a.attributes);\n  return {\n    schemaVersion: 1, id, traceId, name, parentId: str(a.parentId), startTime, endTime,\n    openEnded: a.endTime === undefined || a.openEnded === true,\n    agentId: str(a.agentId) ?? 'unattributed', agentType: str(a.agentType), parentAgentId: str(a.parentAgentId),\n    category: a.category ?? categoryFor(name, at), subtype: str(a.subtype),\n    model: str(a.model), provider: str(a.provider), tool: str(a.tool),\n    inputTokens: nonnegative(a.inputTokens, 'inputTokens'), outputTokens: nonnegative(a.outputTokens, 'outputTokens'),\n    cachedTokens: nonnegative(a.cachedTokens, 'cachedTokens'), cost: nonnegative(a.cost, 'cost'),\n    costCurrency: str(a.costCurrency), latency: nonnegative(a.latency, 'latency'),\n    contextTokens: nonnegative(a.contextTokens, 'contextTokens'), contextLimit: nonnegative(a.contextLimit, 'contextLimit'),\n    retry: nonnegative(a.retry, 'retry'), status: a.status ?? 'unknown',\n    sourceId: str(a.sourceId), targetId: str(a.targetId), targetType: str(a.targetType),\n    links: list(a.links).filter(x => typeof x?.traceId === 'string' && typeof x?.spanId === 'string'),\n    attributes: at, payload: a.payload, raw: a.raw ?? v,\n    observation: a.observation === undefined ? undefined : validateObservation(a.observation),\n  };\n}","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/src/core/ingest.ts#L115-L151","documentation":"normalizedEvent restricts the status field to the closed set ['pending','running','success','error','unknown']. Any other value (wrong casing, synonyms like 'failed' or 'ok', numbers, nulls) is rejected with this error.","triggerScenarios":"Ingesting a record with a.status set to something outside the five allowed literals, e.g. status:'Failed', status:'complete', status:0, or status:null.","commonSituations":"Mapping statuses from another system (HTTP 500 -> 'failed', CI 'passed') without translating to this vocabulary; case sensitivity mistakes ('Success'); tests that reuse fixtures from a different tool.","solutions":["Map the external status into one of pending/running/success/error/unknown before ingest.","Fix casing to exact lowercase literals.","Use 'unknown' when no faithful mapping exists, instead of inventing a value."],"exampleFix":"// before\n{ \"id\": \"a1\", \"traceId\": \"t1\", \"name\": \"step\", \"status\": \"Failed\" }\n// after\n{ \"id\": \"a1\", \"traceId\": \"t1\", \"name\": \"step\", \"status\": \"error\" }","handlingStrategy":"validation","validationCode":"const STATUSES = ['pending', 'running', 'success', 'error', 'unknown'];\nif (record.status !== undefined && !STATUSES.includes(record.status))\n  throw new Error(`status must be one of ${STATUSES.join(', ')}`);","typeGuard":"type Status = 'pending' | 'running' | 'success' | 'error' | 'unknown';\nconst isStatus = (s: unknown): s is Status =>\n  typeof s === 'string' && (['pending','running','success','error','unknown'] as const).includes(s as Status);","tryCatchPattern":"try {\n  traces = importTrace(text, file);\n} catch (e) {\n  if (e instanceof Error && e.message === 'invalid status' || (e instanceof Error && e.message.includes('invalid status')) && e.message.includes('Record')) {\n    console.error('Normalize statuses to the five allowed literals before import');\n  } else throw e;\n}","preventionTips":["Centralize status mapping (e.g. 'Failed' -> 'error') in one producer-side function.","Always lowercase statuses before emitting.","Use 'unknown' as the fallback for unmappable external statuses."],"tags":["validation","enum","ingest"],"backgroundTag":"invalid-enum-value","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}