]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Reformat hint and don't print as part of the error
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 19 Apr 2023 14:18:08 +0000 (16:18 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 19 Apr 2023 20:31:29 +0000 (22:31 +0200)
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.

mkosi/__init__.py
mkosi/log.py

index 7c552129b3a19ef9a93dc156c892612de02f0439..36d363279fa4354aac0bf7e91ca365564a06460c 100644 (file)
@@ -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(
index 9db56f77e63946734c2e0987d0e6ea3e4a398527..42498929ec33ceba7a40149470c636861fae08cd 100644 (file)
@@ -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)