{"record":{"id":"9f3623efe6300a95","repo":"commaai/openpilot","slug":"profile-iccid-not-found","errorCode":null,"errorMessage":"profile {iccid} not found","messagePattern":"profile (.+?) not found","errorType":"exception","errorClass":"LPAError","httpStatus":null,"severity":"error","filePath":"openpilot/common/esim/lpa.py","lineNumber":407,"sourceCode":"  list_ok = find_tag(root, TAG_OK)\n  if list_ok is None:\n    return []\n  return [decode_struct(value, PROFILE) for tag, value in iter_tlv(list_ok) if tag == 0xE3]\n\n\ndef list_profiles(client: AtClient) -> list[dict]:\n  return decode_profiles(es10x_command(client, TAG_PROFILE_INFO_LIST.to_bytes(2, \"big\") + b\"\\x00\"))\n\n\ndef set_profile_nickname(client: AtClient, iccid: str, nickname: str) -> None:\n  nickname_bytes = nickname.encode(\"utf-8\")\n  if len(nickname_bytes) > 64:\n    raise ValueError(\"Profile nickname must be 64 bytes or less\")\n  content = encode_tlv(TAG_ICCID, string_to_tbcd(iccid)) + encode_tlv(0x90, nickname_bytes)\n  response = es10x_command(client, encode_tlv(TAG_SET_NICKNAME, content))\n  code = require_tag(require_tag(response, TAG_SET_NICKNAME, \"SetNicknameResponse\"), TAG_STATUS, \"SetNickname status\")[0]\n  if code == 0x01:\n    raise LPAError(f\"profile {iccid} not found\")\n  if code != 0x00:\n    raise RuntimeError(f\"SetNickname failed with status 0x{code:02X}\")\n\n\n# --- ES9P HTTP ---\n\ndef es9p_request(smdp_address: str, endpoint: str, payload: dict, error_prefix: str = \"Request\", session: requests.Session | None = None) -> dict:\n  url = f\"https://{smdp_address}/gsma/rsp2/es9plus/{endpoint}\"\n  headers = {\"User-Agent\": \"gsma-rsp-lpad\", \"X-Admin-Protocol\": \"gsma/rsp/v2.3.0\", \"Content-Type\": \"application/json\"}\n  http = session or requests\n  resp = http.post(url, json=payload, headers=headers, timeout=HTTP_TIMEOUT, verify=GSMA_CI_BUNDLE)\n  resp.raise_for_status()\n  if not resp.content:\n    return {}\n  data = resp.json()\n  if \"header\" in data and \"functionExecutionStatus\" in data[\"header\"]:\n    status = data[\"header\"][\"functionExecutionStatus\"]\n    if status.get(\"status\") == \"Failed\":","sourceCodeStart":389,"sourceCodeEnd":425,"githubUrl":"https://github.com/commaai/openpilot/blob/516ec1e68203439a73f340f1d0b3b91eabc626ee/openpilot/common/esim/lpa.py#L389-L425","documentation":"After sending the SetNickname request, the eUICC's response status tag is parsed: code 0x01 per PROFILE_ERROR_CODES means iccidOrAidNotFound. The library raises LPAError (specifically the base LPA error, cf. LPAProfileNotFoundError in the base module) so callers can distinguish 'unknown profile' from transport failures.","triggerScenarios":"set_profile_nickname() with an ICCID that does not exist on the eUICC: stale ICCID captured before a delete, typo'd digit, or an ICCID for a different device's eUICC.","commonSituations":"UI holds a cached profile list that is out of date; profile was deleted by another flow; ICCID transcribed with a missing/extra digit (the TBCD encoding also changes if an odd digit count is mishandled).","solutions":["Call list_profiles(client) and use an ICCID from the fresh list","Catch LPAError/LPAProfileNotFoundError specifically to show 'profile not found' rather than a generic failure","Validate the ICCID format (19-20 digits, Luhn) before sending"],"exampleFix":"# before\nset_profile_nickname(client, stale_iccid, 'car')  # LPAError: profile ... not found\n\n# after\nfrom openpilot.common.esim.lpa import list_profiles, set_profile_nickname\n\nlive = {p['iccid'] for p in list_profiles(client)}\nif stale_iccid not in live:\n  raise SystemExit(f'{stale_iccid} no longer on eUICC; profiles: {sorted(live)}')\nset_profile_nickname(client, stale_iccid, 'car')","handlingStrategy":"validation","validationCode":"from openpilot.common.esim.lpa import list_profiles\n\nlive_iccids = {p['iccid'] for p in list_profiles(client)}\nif iccid not in live_iccids:\n  raise SystemExit(f'{iccid} not on eUICC; available: {sorted(live_iccids)}')","typeGuard":"def iccid_exists(client, iccid: str) -> bool:\n  return any(p['iccid'] == iccid for p in list_profiles(client))","tryCatchPattern":"from openpilot.common.esim.base import LPAError\n\ntry:\n  set_profile_nickname(client, iccid, name)\nexcept LPAError as e:\n  if 'not found' in str(e):\n    # refresh and retry once with a live iccid\n    ...\n  raise","preventionTips":["Never cache ICCIDs across user interactions; re-list before operating","Catch LPAError separately from transport errors to give accurate user feedback","Validate ICCID length/Luhn before sending to the eUICC"],"tags":["esim","profile-not-found","stale-state","sgp22","python"],"backgroundTag":null,"analyzedSha":"516ec1e68203439a73f340f1d0b3b91eabc626ee","analyzedAt":"2026-08-15T00:17:37.461Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}