]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Do not print hint about exception for RuntimeError 1463/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 19 Apr 2023 14:21:16 +0000 (16:21 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 19 Apr 2023 20:31:41 +0000 (22:31 +0200)
If debug is already on, the hint is not useful. Also, if we already printed an
error, we don't need to tell the user that we internally used an exception,
this is not relevant to the user.

Also, change str(e) to e.__class__.__name__. 'str(e)' is the same as 'e' here,
and is not guaranteed to contain any message. E.g. for 'raise ValueError',
str(e) is just ''. Let's say "internal exception CLASS" instead.

I still don't think RuntimeError is a great choice. It'd be totally unsuitable
if mkosi was used as a library. We don't do this right now, so it's not so bad,
but we could still get confused by RuntimeError generated in some sloppy code
in one of the packages that we call. This is hopefully unlikely, but our own
custom exception would be clearer and free of this risk. Alas, RuntimeError was
added purposefully in e25d746f9d7668edc5134cde4ec381c8b2da0136, so I'm not
changing it.

mkosi/__main__.py

index abbff3e921166f2d644884ea96de5e4a1bd52e22..69c524f1109198fe3a82f2caf9aac1a2bd0698c4 100644 (file)
@@ -37,8 +37,10 @@ def propagate_failed_return() -> Iterator[None]:
     except Exception as e:
         if ARG_DEBUG:
             raise e
-
-        MkosiPrinter.error(f"Error: {str(e)}, rerun mkosi with --debug run to get more information")
+        elif not isinstance(e, RuntimeError):
+            # RuntimeError is used to wrap generic errors, and the message that was printed should be enough.
+            MkosiPrinter.info(f"Hint: mkosi failed because of an internal exception {e.__class__.__name__}, "
+                              "rerun mkosi with --debug to get more information")
         sys.exit(1)