From a93344b9c0eea857078e9b5681a42cfcc5acb19e Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Mon, 6 Mar 2023 15:23:12 +0100 Subject: [PATCH] component: add RegistryNotReadyError Sounds valueable to have a specific type of error rather than a KeyError when something break because no registry is ready. --- component/core.py | 13 ++++++++----- component/exception.py | 4 ++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/component/core.py b/component/core.py index 45ee64069..aa4cb5250 100644 --- a/component/core.py +++ b/component/core.py @@ -23,7 +23,7 @@ from odoo import models from odoo.tools import LastOrderedSet, OrderedSet -from .exception import NoComponentError, SeveralComponentError +from .exception import NoComponentError, RegistryNotReadyError, SeveralComponentError _logger = logging.getLogger(__name__) @@ -252,14 +252,17 @@ def __init__( dbname = self.env.cr.dbname try: self.components_registry = _component_databases[dbname] - except KeyError: - _logger.error( + except KeyError as exc: + msg = ( "No component registry for database %s. " "Probably because the Odoo registry has not been built " - "yet.", + "yet." + ) + _logger.error( + msg, dbname, ) - raise + raise RegistryNotReadyError(msg) from exc self._propagate_kwargs = ["collection", "model_name", "components_registry"] for attr_name, value in kwargs.items(): setattr(self, attr_name, value) diff --git a/component/exception.py b/component/exception.py index 3883282e8..cb4c67853 100644 --- a/component/exception.py +++ b/component/exception.py @@ -12,3 +12,7 @@ class NoComponentError(ComponentException): class SeveralComponentError(ComponentException): """More than one component have been found""" + + +class RegistryNotReadyError(ComponentException): + """Component registry not ready yet for given DB."""