{"record":{"id":"d5d5e67eada8c83e","repo":"home-assistant/core","slug":"multiple-errors-when-creating-backup-unhandled-e","errorCode":null,"errorMessage":"Multiple errors when creating backup: {unhandled_exc}, {err}","messagePattern":"Multiple errors when creating backup: (.+?), (.+?)","errorType":"exception","errorClass":"BackupManagerExceptionGroup","httpStatus":null,"severity":"error","filePath":"homeassistant/components/backup/manager.py","lineNumber":1889,"sourceCode":"                release_stream=remove_backup,\n            )\n        finally:\n            # Inform integrations the backup is done\n            # If there's an unhandled exception, we keep it so we can rethrow it in case\n            # the post backup actions also fail.\n            unhandled_exc = sys.exception()\n            try:\n                try:\n                    await manager.async_post_backup_actions()\n                except BackupManagerError as err:\n                    raise BackupReaderWriterError(str(err)) from err\n            except Exception as err:\n                if not unhandled_exc:\n                    raise\n                # If there's an unhandled exception, we wrap both that and the exception\n                # from the post backup actions in an ExceptionGroup so the caller is\n                # aware of both exceptions.\n                raise BackupManagerExceptionGroup(\n                    f\"Multiple errors when creating backup: {unhandled_exc}, {err}\",\n                    [unhandled_exc, err],\n                ) from None\n\n    def _mkdir_and_generate_backup_contents(\n        self,\n        backup_data: dict[str, Any],\n        database_included: bool,\n        password: str | None,\n        tar_file_path: Path | None,\n    ) -> tuple[Path, int]:\n        \"\"\"Generate backup contents and return the size.\"\"\"\n        if not tar_file_path:\n            tar_file_path = self.temp_backup_dir / f\"{backup_data['slug']}.tar\"\n        try:\n            make_backup_dir(tar_file_path.parent)\n        except OSError as err:\n            raise BackupReaderWriterError(","sourceCodeStart":1871,"sourceCodeEnd":1907,"githubUrl":"https://github.com/home-assistant/core/blob/58a3fdb3ea0538617f0a07efcfba6294de64fd59/homeassistant/components/backup/manager.py#L1871-L1907","documentation":"BackupManagerExceptionGroup raised when the backup creation already failed with an unhandled exception AND the subsequent async_post_backup_actions() also raised. HA wraps both exceptions in an ExceptionGroup so neither is silently lost; the message embeds both exception reprs.","triggerScenarios":"An exception is active in the current task (sys.exception() is set, e.g. inside an except* block of the create flow) while cleanup/post-backup actions (e.g. notifying agents the backup finished) raise another exception.","commonSituations":"Backup write fails (disk full, agent upload error) and the post-backup hook (agent bookkeeping, event firing) also fails — commonly the same underlying network/disk issue hits both stages; misbehaving custom backup agent raising in both write and finalize callbacks.","solutions":["Inspect the ExceptionGroup's .exceptions — fix the primary (unhandled) exception first, the secondary usually shares the root cause","Check disk space and permissions on the backup/temp directories","If a custom agent raises in both upload and post-backup hooks, make its post-backup handler idempotent and non-raising on failure","Retry the backup after fixing the root cause"],"exampleFix":"# before\ntry:\n    await manager.async_create_backup(...)\nexcept BackupManagerExceptionGroup as eg:\n    raise  # opaque\n# after\ntry:\n    await manager.async_create_backup(...)\nexcept BackupManagerExceptionGroup as eg:\n    for exc in eg.exceptions:\n        _LOGGER.error(\"Backup failure: %r\", exc)\n    raise","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    await manager.async_create_backup(...)\nexcept* BackupManagerExceptionGroup as eg:\n    for exc in eg.exceptions:\n        _LOGGER.error(\"backup failure: %r\", exc)\n    # handle primary (write) failure; secondary is usually collateral","preventionTips":["Custom agents: make async_post_backup handlers idempotent and non-raising","Monitor disk space before large backup jobs","Test the full create path with an agent that fails mid-upload to see how errors group"],"tags":["home-assistant","backup","exception-group","cleanup"],"backgroundTag":null,"analyzedSha":"58a3fdb3ea0538617f0a07efcfba6294de64fd59","analyzedAt":"2026-08-14T20:54:38.818Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}