Skip to content

Commit

Permalink
mformat: provide nice error message instead of traceback for invalid …
Browse files Browse the repository at this point in the history
…value

I ran into this with `option = true;` (not the trailing `;`). Now we
provide a nicer message instead of an uncaught Python traceback.

Closes: mesonbuild#13565
  • Loading branch information
dcbaker committed Aug 19, 2024
1 parent cdf646f commit 8da98f1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion mesonbuild/mformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,13 @@ 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:
value = str(e).split(':')[1].strip()
raise MesonException(
f'Error parsing "{str(configuration_file)}", option "{f.name}" '
f'has invalid value: "{value}"')
if value is not None:
setattr(config, f.name, value)

Expand Down

0 comments on commit 8da98f1

Please sign in to comment.