use custom exceptions to improve error handling

This patch adds the KasUserError exception class to distinguish between
internal kas exceptions and user or configuration errors. Exceptions
previously raised on user errors are ported over by deriving
KasUserError. In case of user errors, only the exception message is
shown, but no stacktrace. This makes it easier for users to locate the
issue as the reason is now stated in the last line of the output.

Kas internal exceptions are not subject to this change to help the
developers to find the root cause more easily.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Felix Moessbauer
2023-05-04 04:50:17 +02:00
committed by Jan Kiszka
parent 6fa40363aa
commit a5750901c6
5 changed files with 78 additions and 5 deletions

View File

@@ -21,7 +21,9 @@
# SOFTWARE.
"""
This module is the main entry point for kas, setup tool for bitbake based
projects
projects. In case of user errors (e.g. invalid configuration, repo fetch
failure) KAS exits with error code 2, while exiting with 1 for internal
errors. For details on error handling, see :mod:`kas.kasusererror`.
"""
import argparse
@@ -32,6 +34,7 @@ import logging
import signal
import sys
import os
from .kasusererror import KasUserError
try:
import colorlog
@@ -173,6 +176,9 @@ def main():
try:
kas(sys.argv[1:])
except KasUserError as err:
logging.error('%s', err)
sys.exit(2)
except Exception as err:
logging.error('%s', err)
traceback.print_exc()