{"record":{"id":"2d18e075e972fbd4","repo":"agalwood/Motrix","slug":"tostatus-is-required","errorCode":null,"errorMessage":"toStatus is required","messagePattern":"toStatus is required","errorType":"validation","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"src/core/inspector-activity/validators.ts","lineNumber":182,"sourceCode":"    input.runtimeGeneration,\n    'runtimeGeneration',\n    MAX_EVENT_KEY_LENGTH\n  )\n  assertPositiveSafeInteger(input.occurredAt, 'occurredAt')\n  assertNonNegativeSafeInteger(input.occurredMonotonicMs, 'occurredMonotonicMs')\n  if (!EVENT_KIND_VALUES.has(input.kind)) {\n    throw new RangeError('kind is not a legal history event kind')\n  }\n  if (!ACCURACY_VALUES.has(input.accuracy)) {\n    throw new RangeError('accuracy is not legal')\n  }\n  if (!DELIVERY_VALUES.has(input.delivery)) {\n    throw new RangeError('delivery is not legal')\n  }\n  assertStatus(input.fromStatus, 'fromStatus')\n  assertStatus(input.toStatus, 'toStatus')\n  if (input.toStatus === null) {\n    throw new RangeError('toStatus is required')\n  }\n  assertBoundedText(input.errorCode, 'errorCode', MAX_ERROR_CODE_LENGTH)\n  assertBoundedText(\n    input.errorMessage,\n    'errorMessage',\n    MAX_ERROR_MESSAGE_LENGTH\n  )\n  assertBoundedText(\n    input.errorDetailKey,\n    'errorDetailKey',\n    MAX_ERROR_DETAIL_KEY_LENGTH\n  )\n  assertBoundedDetailParams(\n    input.errorDetailParams,\n    'errorDetailParams',\n    MAX_ERROR_DETAIL_PARAMS_JSON_LENGTH\n  )\n","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/agalwood/Motrix/blob/1a708ee57746c434e2c67a44bbf0906a976afea4/src/core/inspector-activity/validators.ts#L164-L200","documentation":"`validateHistoryEventInput` allows `fromStatus` to be `null` (for the first transition) but requires `toStatus` to be a concrete `TaskStatus`. After `assertStatus(input.toStatus, ...)` succeeds, this `RangeError` fires only if `toStatus === null`. Every history event must record the status it lands in.","triggerScenarios":"Submitting an event with `toStatus: null` — usually because the producer used `fromStatus ?? toStatus`-style code that resolved to null, or because JSON deserialization defaulted a missing field to null.","commonSituations":"Building an event from a partial engine snapshot where the new status is not yet known; tests using `null` as a placeholder; bridge code forwarding the source's 'no change' sentinel without translating it.","solutions":["Resolve the destination status before constructing the event — defer submission until it is known.","If genuinely unknown, do not emit an event; emit one only at a real transition.","Map the source's 'no change' sentinel to the current persisted status."],"exampleFix":"// before\nevent.toStatus = nextStatus  // nextStatus is null\n// after\nif (nextStatus === null) return  // no transition, no event\nevent.toStatus = nextStatus","handlingStrategy":"validation","validationCode":"if (input.toStatus === null) {\n  // do not submit — no transition to record\n  return\n}","typeGuard":"function hasToStatus<T extends { toStatus: unknown }>(e: T): e is T & { toStatus: string } {\n  return e.toStatus !== null\n}","tryCatchPattern":null,"preventionTips":["Never build an event before its destination status is known.","Guard submission sites with `if (toStatus === null) return`."],"tags":["validation","range-error","state-machine"],"backgroundTag":null,"analyzedSha":"1a708ee57746c434e2c67a44bbf0906a976afea4","analyzedAt":"2026-08-12T16:18:09.346Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}