diff --git a/elasticapm/conf/__init__.py b/elasticapm/conf/__init__.py index 5318d64b5..5b851c9a5 100644 --- a/elasticapm/conf/__init__.py +++ b/elasticapm/conf/__init__.py @@ -275,7 +275,14 @@ def __call__(self, value, field_name): match = re.match(self.regex, value) if match: return value - raise ConfigurationError("{} does not match pattern {}".format(value, self.verbose_pattern), field_name) + raise ConfigurationError( + "{}={} does not match pattern {}".format( + field_name, + value, + self.verbose_pattern, + ), + field_name, + ) class UnitValidator(object): @@ -288,12 +295,19 @@ def __call__(self, value, field_name): value = str(value) match = re.match(self.regex, value, re.IGNORECASE) if not match: - raise ConfigurationError("{} does not match pattern {}".format(value, self.verbose_pattern), field_name) + raise ConfigurationError( + "{}={} does not match pattern {}".format( + field_name, + value, + self.verbose_pattern, + ), + field_name, + ) val, unit = match.groups() try: val = int(val) * self.unit_multipliers[unit] except KeyError: - raise ConfigurationError("{} is not a supported unit".format(unit), field_name) + raise ConfigurationError("{}={} is not a supported unit".format(field_name, unit), field_name) return val @@ -315,7 +329,7 @@ def __call__(self, value, field_name): try: value = float(value) except ValueError: - raise ConfigurationError("{} is not a float".format(value), field_name) + raise ConfigurationError("{}={} is not a float".format(field_name, value), field_name) multiplier = 10**self.precision rounded = math.floor(value * multiplier + 0.5) / multiplier if rounded == 0 and self.minimum and value != 0: @@ -337,8 +351,10 @@ def __init__(self, range_start, range_end, range_desc) -> None: def __call__(self, value, field_name): if self.range_start <= value <= self.range_end: raise ConfigurationError( - "{} cannot be in range: {}".format( - value, self.range_desc.format(**{"range_start": self.range_start, "range_end": self.range_end}) + "{}={} cannot be in range: {}".format( + field_name, + value, + self.range_desc.format(**{"range_start": self.range_start, "range_end": self.range_end}), ), field_name, ) @@ -349,11 +365,11 @@ class FileIsReadableValidator(object): def __call__(self, value, field_name): value = os.path.normpath(value) if not os.path.exists(value): - raise ConfigurationError("{} does not exist".format(value), field_name) + raise ConfigurationError("{}={} does not exist".format(field_name, value), field_name) elif not os.path.isfile(value): - raise ConfigurationError("{} is not a file".format(value), field_name) + raise ConfigurationError("{}={} is not a file".format(field_name, value), field_name) elif not os.access(value, os.R_OK): - raise ConfigurationError("{} is not readable".format(value), field_name) + raise ConfigurationError("{}={} is not readable".format(field_name, value), field_name) return value @@ -384,7 +400,12 @@ def __call__(self, value, field_name): ret = self.valid_values.get(value.lower()) if ret is None: raise ConfigurationError( - "{} is not in the list of valid values: {}".format(value, list(self.valid_values.values())), field_name + "{}={} is not in the list of valid values: {}".format( + field_name, + value, + list(self.valid_values.values()), + ), + field_name, ) return ret