{"record":{"id":"6a1ced66f41266a7","repo":"diegosouzapw/OmniRoute","slug":"lease-context-invalid","errorCode":"LEASE_CONTEXT_INVALID","errorMessage":"Malformed lease owner","messagePattern":"Malformed lease owner","errorType":"error_code","errorClass":"LeaseContextError","httpStatus":400,"severity":"error","filePath":"src/sse/services/leaseContext.ts","lineNumber":54,"sourceCode":"\nexport function validateExclusiveLeaseKeyConfiguration(\n  metadata: LeaseKeyMetadata | null | undefined\n): void {\n  if (!isExclusiveLeaseManagedKey(metadata)) return;\n  if (!metadata?.allowedConnections?.length)\n    throw new LeaseContextError(\n      403,\n      \"LEASE_KEY_CONFIGURATION_INVALID\",\n      \"Exclusive lease keys require explicit allowed connections\"\n    );\n}\n\nexport function parseLeaseOwnerHeader(headers: Headers): string {\n  const leaseOwnerId = headers.get(LEASE_OWNER_HEADER)?.trim() ?? \"\";\n  if (!leaseOwnerId)\n    throw new LeaseContextError(400, \"LEASE_CONTEXT_REQUIRED\", \"Explicit lease owner required\");\n  if (!LEASE_OWNER_PATTERN.test(leaseOwnerId))\n    throw new LeaseContextError(400, \"LEASE_CONTEXT_INVALID\", \"Malformed lease owner\");\n  return leaseOwnerId;\n}\n\nexport function parseManagedLeaseRequestContext(headers: Headers): ManagedLeaseRequestContext {\n  const leaseOwnerId = parseLeaseOwnerHeader(headers);\n  const rawGeneration = headers.get(LEASE_GENERATION_HEADER)?.trim() ?? \"\";\n  if (!/^[1-9]\\d*$/.test(rawGeneration))\n    throw new LeaseContextError(400, \"LEASE_CONTEXT_INVALID\", \"Positive lease generation required\");\n  const generation = Number(rawGeneration);\n  if (!Number.isSafeInteger(generation))\n    throw new LeaseContextError(\n      400,\n      \"LEASE_CONTEXT_INVALID\",\n      \"The lease generation header is invalid\"\n    );\n  return { leaseOwnerId, generation };\n}\n","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/sse/services/leaseContext.ts#L36-L72","documentation":"LeaseContextError thrown by parseLeaseOwnerHeader() when the lease-owner header is present but its value fails validation (malformed owner identifier, not merely missing). Guards lease bookkeeping against garbage owner ids that would corrupt attribution.","triggerScenarios":"Thrown at src/sse/services/leaseContext.ts:54 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Send a well-formed lease owner identifier in LEASE_OWNER_HEADER (check expected format in leaseContext.ts)","Re-generate the owner id if the client stored a corrupted value","Validate owner ids at creation time so malformed ones never reach lease headers","Return 400 to the caller with the lease error code for diagnostics"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}