From 19d5bc226246d7e7a832d5fc3f8a78c5431018a5 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Fri, 4 Jul 2025 16:26:05 +0200 Subject: [PATCH] Better handled assertion and programmer errors Signed-off-by: Ole Herman Schumacher Elgesem --- cfbs/main.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cfbs/main.py b/cfbs/main.py index 19154580..b1844805 100644 --- a/cfbs/main.py +++ b/cfbs/main.py @@ -5,6 +5,7 @@ import logging as log import sys +import os from typing import Union from cfbs.result import Result @@ -246,6 +247,10 @@ def main() -> int: The only thing we want to do here is call _main() and handle exceptions (errors). """ + if os.getenv("CFBACKTRACE") == "1": + r = _main() + assert type(r) is int + return r try: r = _main() # TODO: I'm not exactly sure when the commands @@ -256,5 +261,13 @@ def main() -> int: print("Error: " + str(e)) except GenericExitError as e: print("Error: " + str(e)) + except (AssertionError, ProgrammerError) as e: + print("Error: " + str(e)) + print( + "This is an unexpected error indicating a bug, please create a ticket at:" + ) + print("https://northerntech.atlassian.net/") + print("(Rerun with CFBACKTRACE=1 in front of your command to show backtraces)") + # TODO: Handle other exceptions return 1