From 25ba3a262ea32d18111549b6f394412305589842 Mon Sep 17 00:00:00 2001 From: Evan Pete Walsh Date: Thu, 16 Apr 2020 15:05:36 -0700 Subject: [PATCH] Fix error message when top level config key missing (#4081) --- allennlp/common/params.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/allennlp/common/params.py b/allennlp/common/params.py index d17481de342..4db24911a56 100644 --- a/allennlp/common/params.py +++ b/allennlp/common/params.py @@ -236,7 +236,10 @@ def pop(self, key: str, default: Any = DEFAULT, keep_as_dict: bool = False) -> A try: value = self.params.pop(key) except KeyError: - raise ConfigurationError(f'key "{key}" is required at location "{self.history}"') + msg = f'key "{key}" is required' + if self.history: + msg += f' at location "{self.history}"' + raise ConfigurationError(msg) else: value = self.params.pop(key, default)