From 72f3ad9549e84bdba7bdfd97d2ede3c55e02f103 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Wed, 8 Oct 2025 16:41:36 -0400 Subject: [PATCH] script/build-with-container: improve error handling for invalid distros Instead of throwing a long obnoxious traceback at the user if the value supplied to -d/--distro is invalid do something nicer. For example: ``` $ ./src/script/build-with-container.py -d trixy -e build usage: build-with-container.py [-h] [--help-build-steps] build-with-container.py: error: argument --distro/-d: unknown distro: 'trixy' not in centos10, centos10stream, centos8, centos9, centos9stream, rocky9, rockylinux9, rocky10, rockylinux10, fedora41, fc41, fedora42, fc42, fedora43, fc43, ubuntu20.04, ubuntu-focal, focal, ubuntu22.04, ubuntu-jammy, jammy, ubuntu24.04, ubuntu-noble, noble, debian12, debian-bookworm, bookworm, debian13, debian-trixie, trixie ``` Signed-off-by: John Mulligan --- src/script/build-with-container.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/script/build-with-container.py b/src/script/build-with-container.py index 553b6b722e82d..6c6f82abd8b31 100755 --- a/src/script/build-with-container.py +++ b/src/script/build-with-container.py @@ -173,7 +173,12 @@ class DistroKind(StrEnum): @classmethod def from_alias(cls, value): - return cls.aliases()[value] + try: + return cls.aliases()[value] + except KeyError: + valid = ", ".join(sorted(cls.aliases())) + msg = f"unknown distro: {value!r} not in {valid}" + raise argparse.ArgumentTypeError(msg) class DefaultImage(StrEnum): -- 2.39.5