From ac9ae74a0b3b4a3825fc9d47a3dbf3c472e2f45f Mon Sep 17 00:00:00 2001 From: clerie Date: Thu, 16 Jun 2022 23:00:22 +0200 Subject: [PATCH] Make the exception show you all unknown keys at once In case a response type contains an unknown key, there are probably some more. --- mitel_ommclient2/types/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mitel_ommclient2/types/__init__.py b/mitel_ommclient2/types/__init__.py index dad1db1..29c03dc 100644 --- a/mitel_ommclient2/types/__init__.py +++ b/mitel_ommclient2/types/__init__.py @@ -39,12 +39,16 @@ class ChildType: return "{}({})".format(self.__class__.__name__, repr(self._attrs)) def cast_dict_to_childtype(t, d): + errors = {} # collect unknown keys for k, v in d.items(): if k in t.FIELDS.keys(): if t.FIELDS[k] is not None and type(v) != t.FIELDS[k]: d[k] = t.FIELDS[k](v) else: - raise KeyError("Key '{}' containing '{}' is unknown for {}".format(k, v, t.__name__)) + errors[k] = v + + if errors != {}: + raise KeyError("The following keys are unknown for '{}': {}".format(t.__name__, errors)) return t(d)