{"record":{"id":"e5d0ebf724ff4227","repo":"commaai/openpilot","slug":"deleteprofile-failed-profile-error-codes-get-cod","errorCode":null,"errorMessage":"DeleteProfile failed: {PROFILE_ERROR_CODES.get(code, 'unknown')} (0x{code:02X})","messagePattern":"DeleteProfile failed: (.+?) \\(0x(.+?)\\)","errorType":"exception","errorClass":"LPAError","httpStatus":null,"severity":"error","filePath":"openpilot/common/esim/lpa.py","lineNumber":748,"sourceCode":"\n  def process_notifications(self) -> None:\n    if not system_time_valid():\n      raise RuntimeError(\"System time is not set; TLS certificate validation requires a valid clock\")\n    with self._acquire_channel():\n      process_notifications(self._client)\n\n  def delete_profile(self, iccid: str) -> None:\n    profile = next((p for p in self.list_profiles() if p.iccid == iccid), None)\n    if profile is None:\n      raise LPAProfileNotFoundError(f\"profile not found: {iccid}\")\n    if profile.is_comma:\n      raise LPAError(\"refusing to delete a comma profile\")\n    with self._acquire_channel():\n      request = encode_tlv(TAG_DELETE_PROFILE, encode_tlv(TAG_ICCID, string_to_tbcd(iccid)))\n      response = es10x_command(self._client, request)\n      code = require_tag(require_tag(response, TAG_DELETE_PROFILE, \"DeleteProfileResponse\"), TAG_STATUS, \"DeleteProfile status\")[0]\n    if code != PROFILE_OK:\n      raise LPAError(f\"DeleteProfile failed: {PROFILE_ERROR_CODES.get(code, 'unknown')} (0x{code:02X})\")\n\n  def download_profile(self, qr: str, nickname: str | None = None) -> None:\n    with self._acquire_channel():\n      iccid = download_profile(self._client, qr)\n      if nickname and iccid:\n        set_profile_nickname(self._client, iccid, nickname)\n\n  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:","sourceCodeStart":730,"sourceCodeEnd":766,"githubUrl":"https://github.com/commaai/openpilot/blob/516ec1e68203439a73f340f1d0b3b91eabc626ee/openpilot/common/esim/lpa.py#L730-L766","documentation":"Raised when the eUICC's DeleteProfile response carries a status code other than PROFILE_OK. The hex status and its name from PROFILE_ERROR_CODES are included (e.g. ICCID not found, profile enabled, eUICC memory error).","triggerScenarios":"Calling delete_profile on an enabled profile (many eUICCs require disable first), an ICCID unknown to the eUICC, or while another profile operation holds the eUICC.","commonSituations":"Deleting the currently active/enabled profile; concurrent profile operations; stale ICCID after a profile switch.","solutions":["Disable/switch away from the profile before deleting it","Retry with the exact ICCID from a fresh list_profiles()","Process pending notifications, then retry — install notifications can block deletes on some eUICCs"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"profile = next((p for p in lpa.list_profiles() if p.iccid == iccid), None)\nif profile is not None and profile.enabled:\n    switch_or_disable_first()  # eUICCs often refuse deleting enabled profiles","typeGuard":null,"tryCatchPattern":"try:\n    lpa.delete_profile(iccid)\nexcept LPAError as e:\n    if \"DeleteProfile failed\" in str(e):\n        lpa.process_notifications()\n        lpa.delete_profile(iccid)  # one retry after clearing notifications","preventionTips":["Disable profiles before deletion","Process pending notifications before profile management operations"],"tags":["esim","lpa","euicc","profile-management"],"backgroundTag":null,"analyzedSha":"516ec1e68203439a73f340f1d0b3b91eabc626ee","analyzedAt":"2026-08-15T00:17:37.461Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}