From 9e11b886a764240bebe97898bfd15535d3dfe847 Mon Sep 17 00:00:00 2001 From: Hook25 Date: Thu, 31 Oct 2024 10:37:50 +0100 Subject: [PATCH] Better unit invalid exception --- checkbox-ng/plainbox/impl/unit/unit.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/checkbox-ng/plainbox/impl/unit/unit.py b/checkbox-ng/plainbox/impl/unit/unit.py index b1c62426ce..f8bdbaed30 100644 --- a/checkbox-ng/plainbox/impl/unit/unit.py +++ b/checkbox-ng/plainbox/impl/unit/unit.py @@ -83,15 +83,25 @@ class MissingParam(Exception): the name of the missing parameter. """ - def __init__(self, parameter): + def __init__(self, template_id, field, value, parameter): + self.template_id = template_id + self.field = field + self.value = value self.parameter = parameter def __str__(self): - return _("failed to find value for paramter {}").format(self.parameter) + return ( + "Template '{}' generated an invalid unit. Field '{}' has value " + "'{}' but the template-resource didn't generate any value for " + "'{}'" + ).format(self.template_id, self.field, self.value, self.parameter) def __repr__(self): - return "<{} paramter:{}>".format( - self.__class__.__name__, self.parameter + return "<{} template_id:{} field: {} paramter:{}>".format( + self.__class__.__name__, + self.template_id, + self.field, + self.parameter, ) @@ -708,7 +718,9 @@ def get_record_value(self, name, default=None): value, (), self.parameters ) except KeyError as e: - raise MissingParam(e.args[0]) + raise MissingParam( + self.template_id, name, value, e.args[0] + ) elif ( value is not None and self.template_engine == "jinja2"