From: Zbigniew Jędrzejewski-Szmek Date: Wed, 19 Apr 2023 14:18:08 +0000 (+0200) Subject: Reformat hint and don't print as part of the error X-Git-Tag: v15~229^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=807d632a3e1cc466481e40969a39eeff44dec00f;p=thirdparty%2Fmkosi.git Reformat hint and don't print as part of the error The error about SecureBoot keys was line-broken in the source code and looked strange on the tty: the line break was in the middle of the terminal. Let's rework things a bit to print the hint in gray and print the two filenames at the end so it is easy to select-and-paste into an actual command. Also use hint= in other cases where part of the error is advisory. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 7c552129b..36d363279 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -1220,17 +1220,15 @@ def load_args(args: argparse.Namespace) -> MkosiConfig: if args.secure_boot and args.verb != Verb.genkey: if args.secure_boot_key is None: - die( - "UEFI SecureBoot enabled, but couldn't find private key. (Consider placing it in mkosi.secure-boot.key?)" - ) # NOQA: E501 + die("UEFI SecureBoot enabled, but couldn't find private key.", + hint="Consider placing it in mkosi.secure-boot.key") if args.secure_boot_certificate is None: - die( - "UEFI SecureBoot enabled, but couldn't find certificate. (Consider placing it in mkosi.secure-boot.crt?)" - ) # NOQA: E501 + die("UEFI SecureBoot enabled, but couldn't find certificate.", + hint="Consider placing it in mkosi.secure-boot.crt") if args.sign_expected_pcr is True and not shutil.which("systemd-measure"): - die("Couldn't find systemd-measure binary. It is needed for the --sign-expected-pcr option.") + die("Couldn't find systemd-measure needed for the --sign-expected-pcr option.") if args.sign_expected_pcr is None: args.sign_expected_pcr = bool(shutil.which("systemd-measure")) @@ -2328,15 +2326,9 @@ def generate_secure_boot_key(config: MkosiConfig) -> None: for f in (config.secure_boot_key, config.secure_boot_certificate): if f and not config.force: - die( - dedent( - f"""\ - {f} already exists. - If you are sure you want to generate new secure boot keys - remove {config.secure_boot_key} and {config.secure_boot_certificate} first. - """ - ) - ) + die(f"{f} already exists", + hint=("To generate new secure boot keys, " + f"first remove {config.secure_boot_key} {config.secure_boot_certificate}")) MkosiPrinter.print_step(f"Generating secure boot keys rsa:{keylength} for CN {cn!r}.") MkosiPrinter.info( diff --git a/mkosi/log.py b/mkosi/log.py index 9db56f77e..42498929e 100644 --- a/mkosi/log.py +++ b/mkosi/log.py @@ -6,8 +6,14 @@ from typing import Any, Iterator, NoReturn, Optional ARG_DEBUG: set[str] = set() -def die(message: str, exception: Optional[Exception] = None) -> NoReturn: +def die( + message: str, + exception: Optional[Exception] = None, + *, + hint: Optional[str] = None) -> NoReturn: MkosiPrinter.error(f"Error: {message}") + if hint: + MkosiPrinter.info(f"({hint})") raise exception or RuntimeError(message)