From 1e6e4c8d571e3bd415f9b8285f6f33170ba81761 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 19 Aug 2024 14:29:44 -0700 Subject: [PATCH] mformat: provide nice error message instead of backtrace for invalid value I ran into this with `option = true;` (note the trailing `;`). Now we provide a nicer message instead of an uncaught Python backtrace. Closes: #13565 --- mesonbuild/mformat.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mesonbuild/mformat.py b/mesonbuild/mformat.py index 27f97b4fa5fb..567d1f46df4c 100644 --- a/mesonbuild/mformat.py +++ b/mesonbuild/mformat.py @@ -861,7 +861,11 @@ def load_configuration(self, configuration_file: T.Optional[Path]) -> FormatterC for f in fields(config): getter = f.metadata['getter'] - value = getter(cp, cp.default_section, f.name, fallback=None) + try: + value = getter(cp, cp.default_section, f.name, fallback=None) + except ValueError as e: + raise MesonException( + f'Error parsing "{str(configuration_file)}", option "{f.name}", error: "{e!s}"') if value is not None: setattr(config, f.name, value)