diff options
| author | 2021-03-26 15:03:56 +0100 | |
|---|---|---|
| committer | 2021-03-26 15:03:56 +0100 | |
| commit | c619a98e6ce16298e999d18667b86ee9f094b550 (patch) | |
| tree | 46a77777de1021ab1e6e73a10f49fa445116ade9 | |
| parent | Branding: raise on non-200 responses (diff) | |
Branding: raise custom error when constructing remote objects
The default KeyError message from dict lookup is just the missing key.
In order to give more context in the log message, we raise our own.
| -rw-r--r-- | bot/exts/backend/branding/_repository.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/bot/exts/backend/branding/_repository.py b/bot/exts/backend/branding/_repository.py index 715361c5d..91a95ae3a 100644 --- a/bot/exts/backend/branding/_repository.py +++ b/bot/exts/backend/branding/_repository.py @@ -43,6 +43,9 @@ class RemoteObject: def __init__(self, dictionary: t.Dict[str, t.Any]) -> None: """Initialize by grabbing annotated attributes from `dictionary`.""" + missing_keys = self.__annotations__.keys() - dictionary.keys() + if missing_keys: + raise KeyError(f"Fetched object lacks expected keys: {missing_keys}") for annotation in self.__annotations__: setattr(self, annotation, dictionary[annotation]) |