{"record":{"id":"676338eac1274065","repo":"commaai/openpilot","slug":"enableprofile-failed-profile-error-codes-get-cod","errorCode":null,"errorMessage":"EnableProfile failed: {PROFILE_ERROR_CODES.get(code, 'unknown')} (0x{code:02X})","messagePattern":"EnableProfile failed: (.+?) \\(0x(.+?)\\)","errorType":"exception","errorClass":"LPAError","httpStatus":null,"severity":"error","filePath":"openpilot/common/esim/lpa.py","lineNumber":774,"sourceCode":"  def nickname_profile(self, iccid: str, nickname: str) -> None:\n    with self._acquire_channel():\n      set_profile_nickname(self._client, iccid, nickname)\n\n  def _enable_profile(self, iccid: str) -> int:\n    inner = encode_tlv(TAG_OK, encode_tlv(TAG_ICCID, string_to_tbcd(iccid)))\n    inner += b'\\x01\\x01\\x01'  # refreshFlag=1\n    response = es10x_command(self._client, encode_tlv(TAG_ENABLE_PROFILE, inner))\n    return require_tag(require_tag(response, TAG_ENABLE_PROFILE, \"EnableProfileResponse\"), TAG_STATUS, \"EnableProfile status\")[0]\n\n  def switch_profile(self, iccid: str) -> None:\n    with self._acquire_channel():\n      code = self._enable_profile(iccid)\n      if code == PROFILE_CAT_BUSY:  # stale eUICC transaction, reset and retry\n        self._client._reset_modem()\n        self._client.open_isdr()\n        code = self._enable_profile(iccid)\n      if code not in (PROFILE_OK, PROFILE_NOT_IN_DISABLED_STATE):\n        raise LPAError(f\"EnableProfile failed: {PROFILE_ERROR_CODES.get(code, 'unknown')} (0x{code:02X})\")\n\n  def is_euicc(self) -> bool:\n    # +CCHO:<n> -> ISD-R applet present, eUICC. Any error -> non-eUICC.\n    with self._acquire_lock():\n      try:\n        lines = self._client.query(f'AT+CCHO=\"{ISDR_AID}\"')\n      except RuntimeError:\n        return False\n      for line in lines:\n        if line.startswith(\"+CCHO:\") and (ch := line.split(\":\", 1)[1].strip()):\n          try:\n            self._client.query(f\"AT+CCHC={ch}\")\n          except (RuntimeError, TimeoutError):\n            pass\n          self._client.channel = None\n          return True\n      return False\n","sourceCodeStart":756,"sourceCodeEnd":792,"githubUrl":"https://github.com/commaai/openpilot/blob/516ec1e68203439a73f340f1d0b3b91eabc626ee/openpilot/common/esim/lpa.py#L756-L792","documentation":"switch_profile() enables a profile via EnableProfile; after one retry following a CAT-busy reset, any status code besides PROFILE_OK or PROFILE_NOT_IN_DISABLED_STATE raises LPAError with the status name and hex code.","triggerScenarios":"switch_profile(iccid) where the ICCID is unknown, the target profile is already enabled (accepted) but the eUICC returns a different error, or a concurrent CAT/modem transaction keeps it busy past the built-in reset+retry.","commonSituations":"Switching to a profile that was deleted; eUICC in a stuck transaction state that survives one modem reset; unsupported profile state transitions on older eUICC firmware.","solutions":["Verify the ICCID exists via list_profiles() before switching","Retry after a full modem reset / power cycle to clear stuck eUICC state","Update AGNOS/modem firmware if the eUICC repeatedly returns unknown status codes"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"assert any(p.iccid == iccid for p in lpa.list_profiles()), \"unknown ICCID\"","typeGuard":null,"tryCatchPattern":"try:\n    lpa.switch_profile(iccid)\nexcept LPAError as e:\n    if \"EnableProfile failed\" in str(e):\n        lpa._client._reset_modem()\n        lpa.switch_profile(iccid)","preventionTips":["Validate the ICCID exists before switching","Reset the modem to clear stuck eUICC transactions before retrying"],"tags":["esim","lpa","euicc","profile-management"],"backgroundTag":null,"analyzedSha":"516ec1e68203439a73f340f1d0b3b91eabc626ee","analyzedAt":"2026-08-15T00:17:37.461Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}