Skip to content

Commit c0cef78

Browse files
committed
loader: Fix error message for invalid enum values
Currently if you use --freebsd/toolchain=invalid-value, you get a big stack trace pointing at this code with the final two lines giving two copies of the error message intended for the user (along with calling it and unhaldned exception). Fix this by raising ValueError instead as caught by the calling code. Also print the enums in kebab-case rather than snake_case to match the --help output and how we expect users to provide these values.
1 parent 7dea59d commit c0cef78

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

pycheribuild/config/loader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ def __call__(self, astring: "Union[str, list[str], EnumTy]") -> "Union[EnumTy, l
100100
return e
101101
v = self.enums[enum_value_name]
102102
except KeyError:
103-
msg = ", ".join([t.name.lower() for t in self.enums])
103+
msg = ", ".join([t.name.lower().replace("_", "-") for t in self.enums])
104104
msg = f"{name}: use one of {{{msg}}}"
105-
raise argparse.ArgumentTypeError(msg)
105+
raise ValueError(msg)
106106
# else:
107107
# self.action.choices = None # hugly hack to prevent post validation from choices
108108
return v

0 commit comments

Comments
 (0)