{"record":{"id":"e574101fda6880f4","repo":"diegosouzapw/OmniRoute","slug":"failed-to-create-command-code-auth-session","errorCode":null,"errorMessage":"Failed to create Command Code auth session","messagePattern":"Failed to create Command Code auth session","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/db/commandCodeAuth.ts","lineNumber":127,"sourceCode":"export function createPendingCommandCodeAuthSession(input: {\n  stateHash: string;\n  expiresAt: string;\n}): CommandCodeAuthSafeStatus {\n  const id = randomUUID();\n  const now = nowIso();\n  db()\n    .prepare(\n      `INSERT INTO command_code_auth_sessions (\n        id, state_hash, status, encrypted_api_key, metadata_json,\n        created_at, expires_at, received_at, applied_at, updated_at\n      ) VALUES (?, ?, 'pending', NULL, NULL, ?, ?, NULL, NULL, ?)`\n    )\n    .run(id, input.stateHash, now, input.expiresAt, now);\n\n  const row = db()\n    .prepare<AuthSessionRow>(\"SELECT * FROM command_code_auth_sessions WHERE id = ?\")\n    .get(id);\n  if (!row) throw new Error(\"Failed to create Command Code auth session\");\n  return toSafeStatus(row);\n}\n\nexport function markCommandCodeAuthSessionReceived(input: {\n  stateHash: string;\n  apiKey: string;\n  metadata?: CommandCodeAuthMetadata;\n}): CommandCodeAuthSafeStatus | null {\n  const now = nowIso();\n  markExpiredForState(input.stateHash, now);\n  const metadata: CommandCodeAuthMetadata = {\n    ...(input.metadata || {}),\n    receivedAt: now,\n  };\n  const encryptedApiKey = encrypt(input.apiKey);\n  db()\n    .prepare(\n      `UPDATE command_code_auth_sessions","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/lib/db/commandCodeAuth.ts#L109-L145","documentation":"Error \"Failed to create Command Code auth session\" thrown in diegosouzapw/OmniRoute.","triggerScenarios":"Thrown at src/lib/db/commandCodeAuth.ts:127 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","schemaVersion":2},"datasetVersion":"2026-08-25T21:54:21.419Z"}