Raise on invalid version strings
@@ -181,9 +181,7 @@ class Cli:
target = args.target
os_name = args.host
qt_version = args.qt_version
- if not Cli._is_valid_version_str(qt_version):
- self.logger.error("Invalid version: '{}'! Please use the form '5.X.Y'.".format(qt_version))
- exit(1)
+ Cli._validate_version_str(qt_version)
keep = args.keep
output_dir = args.outputdir
if output_dir is None:
@@ -278,9 +276,7 @@ class Cli:
target = args.target
os_name = args.host
qt_version = args.qt_version
- if not Cli._is_valid_version_str(qt_version):
- self.logger.error("Invalid version: '{}'! Please use the form '5.X.Y'.".format(qt_version))
- exit(1)
+ Cli._validate_version_str(qt_version)
output_dir = args.outputdir
if output_dir is None:
base_dir = os.getcwd()
@@ -447,9 +443,7 @@ class Cli:
raise CliInputError("'{0.target}' is not a valid target for host '{0.host}'".format(args))
for version_str in (args.modules, args.extensions, args.arch):
- if not Cli._is_valid_version_str(version_str, allow_latest=True, allow_empty=True):
- self.logger.error("Invalid version: '{}'! Please use the form '5.X.Y'.".format(version_str))
- exit(1) # TODO: maybe return 1 instead?
+ Cli._validate_version_str(version_str, allow_latest=True, allow_empty=True)
spec = None
try:
@@ -780,14 +774,13 @@ class Cli:
Settings.load_settings()
@staticmethod
- def _is_valid_version_str(version_str: str, *, allow_latest: bool = False, allow_empty: bool = False) -> bool:
+ def _validate_version_str(version_str: str, *, allow_latest: bool = False, allow_empty: bool = False):
if (allow_latest and version_str == "latest") or (allow_empty and not version_str):
- return True
+ return
try:
Version(version_str)
- return True
- except ValueError:
- return False
+ except ValueError as e:
+ raise CliInputError(f"Invalid version: '{version_str}'! Please use the form '5.X.Y'.") from e
def run_installer(archives: List[QtPackage], base_dir: str, sevenzip: Optional[str], keep: bool):
