aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Matteo Bertucci <[email protected]>2021-04-17 18:37:44 +0200
committerGravatar Matteo Bertucci <[email protected]>2021-04-17 18:37:44 +0200
commit0e4fd3d2d0ae4b0f403cc8f163c783284aefae56 (patch)
tree0a43a9485e6ef44424e378ec40b33f5df5dc1c50
parentMerge remote-tracking branch 'origin/main' into feat/1365/add-bot-badges-to-user (diff)
Make YAMLGetter raise AttributeError instead of KeyError
Utility functions such as hasattr or getattr except __getattribute__ to raise AttributeError not KeyError. This commit also lowers the logging level of the error message to info since it is up to the caller to decide if this is an expected failure or not.
-rw-r--r--bot/constants.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/bot/constants.py b/bot/constants.py
index dc9cd4dfb..3254c2761 100644
--- a/bot/constants.py
+++ b/bot/constants.py
@@ -175,13 +175,14 @@ class YAMLGetter(type):
if cls.subsection is not None:
return _CONFIG_YAML[cls.section][cls.subsection][name]
return _CONFIG_YAML[cls.section][name]
- except KeyError:
+ except KeyError as e:
dotted_path = '.'.join(
(cls.section, cls.subsection, name)
if cls.subsection is not None else (cls.section, name)
)
- log.critical(f"Tried accessing configuration variable at `{dotted_path}`, but it could not be found.")
- raise
+ # Only an INFO log since this can be caught through `hasattr` or `getattr`.
+ log.info(f"Tried accessing configuration variable at `{dotted_path}`, but it could not be found.")
+ raise AttributeError(repr(name)) from e
def __getitem__(cls, name):
return cls.__getattr__(name)