From: Zbigniew Jędrzejewski-Szmek Date: Wed, 19 Apr 2023 14:21:16 +0000 (+0200) Subject: Do not print hint about exception for RuntimeError X-Git-Tag: v15~229^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1463%2Fhead;p=thirdparty%2Fmkosi.git Do not print hint about exception for RuntimeError 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. --- diff --git a/mkosi/__main__.py b/mkosi/__main__.py index abbff3e92..69c524f11 100644 --- a/mkosi/__main__.py +++ b/mkosi/__main__.py @@ -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)