{"record":{"id":"7eebc6e72d20cca4","repo":"commaai/openpilot","slug":"invalid-activation-code-format","errorCode":null,"errorMessage":"Invalid activation code format","messagePattern":"Invalid activation code format","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openpilot/common/esim/lpa.py","lineNumber":614,"sourceCode":"\n\ndef parse_metadata(b64_metadata: str) -> dict:\n  root = find_tag(b64d(b64_metadata), TAG_PROFILE_METADATA)\n  if root is None:\n    raise RuntimeError(\"Invalid profileMetadata\")\n  return decode_struct(root, PROFILE)\n\n\ndef cancel_session(client: AtClient, transaction_id: bytes, reason: int = 127) -> str:\n  content = encode_tlv(0x80, transaction_id) + encode_tlv(0x81, bytes([reason]))\n  response = es10x_command(client, encode_tlv(TAG_CANCEL_SESSION, content))\n  return b64e(response)\n\n\ndef parse_lpa_activation_code(activation_code: str) -> tuple[str, str]:\n  \"\"\"Parse 'LPA:1$smdp.example.com$MATCHING-ID' into (smdp_address, matching_id).\"\"\"\n  if not activation_code.startswith(\"LPA:\"):\n    raise ValueError(\"Invalid activation code format\")\n  parts = activation_code[4:].split(\"$\")\n  if len(parts) != 3:\n    raise ValueError(\"Invalid activation code format\")\n  return parts[1], parts[2]\n\n\ndef _b64_field(data: dict, key: str) -> str:\n  return base64_trim(data[key])\n\n\ndef _cancel_session_safe(client: AtClient, smdp: str, tx_id: str, session: requests.Session) -> None:\n  b64_cancel = \"\"\n  try:\n    b64_cancel = cancel_session(client, b64d(tx_id))\n  except Exception:\n    pass\n  try:\n    es9p_request(smdp, \"cancelSession\", {\"transactionId\": tx_id, \"cancelSessionResponse\": b64_cancel}, \"CancelSession\", session=session)","sourceCodeStart":596,"sourceCodeEnd":632,"githubUrl":"https://github.com/commaai/openpilot/blob/516ec1e68203439a73f340f1d0b3b91eabc626ee/openpilot/common/esim/lpa.py#L596-L632","documentation":"parse_lpa_activation_code() raises ValueError when the string does not start with 'LPA:'. The expected format is 'LPA:1$smdp.example.com$MATCHING-ID' (GSMA activation code).","triggerScenarios":"Passing an activation code like '1$smdp$mid' or a raw SM-DP+ URL without the LPA: prefix to download_profile/parse_lpa_activation_code.","commonSituations":"User scans a non-standard QR code; the code was copy-pasted with the prefix stripped or whitespace-prefixed; a QR containing a raw URL is used instead of an activation code.","solutions":["Use a standard GSMA activation code starting with 'LPA:1$'","Strip whitespace/newlines from scanned QR content before passing it in","If only a host is available, construct the code as f\"LPA:1${host}$\""],"exampleFix":"// before\ndownload_profile(client, \"smdp.example.com\")\n\n// after\ndownload_profile(client, \"LPA:1$smdp.example.com$\")","handlingStrategy":"validation","validationCode":"def is_activation_code(s: str) -> bool:\n    s = s.strip()\n    return s.startswith(\"LPA:\") and len(s[4:].split(\"$\")) == 3","typeGuard":null,"tryCatchPattern":"try:\n    smdp, mid = parse_lpa_activation_code(code)\nexcept ValueError:\n    # prompt user to rescan QR\n    ...","preventionTips":["Strip whitespace from scanned QR content","Validate the LPA: prefix before starting the download flow"],"tags":["esim","lpa","validation","qr"],"backgroundTag":null,"analyzedSha":"516ec1e68203439a73f340f1d0b3b91eabc626ee","analyzedAt":"2026-08-15T00:17:37.461Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}