From 8e801329e005b320703f4b8630c171f52e2a08dc Mon Sep 17 00:00:00 2001 From: Faraphel Date: Fri, 19 Aug 2022 23:58:47 +0200 Subject: [PATCH] if the traceback is too long in the gui, only keep the 5 first and 5 last lines of the traceback --- assets/language/en.json | 6 +++++- assets/language/fr.json | 6 +++++- source/gui/__init__.py | 8 +++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/assets/language/en.json b/assets/language/en.json index cdc77d0..ed0fbf4 100644 --- a/assets/language/en.json +++ b/assets/language/en.json @@ -95,6 +95,10 @@ "CANNOT_FIND_TOOL": "Can't find tool", "IN_TOOLS_DIRECTORY": "in the tools directory.", "CANNOT_EXTRACT_A_DIRECTORY": "Can't extract a directory", - "CANNOT_FIND_SLOT": "Can't find slot" + "CANNOT_FIND_SLOT": "Can't find slot", + "FORBIDDEN_TRACKGROUP_ATTRIBUTE": "Forbidden TrackGroup attribute", + "SAFE_EVAL_ERROR": "Safe eval error", + "TEMPLATE_USED": "Template used", + "MORE_IN_ERROR_LOG": "More information in the error.log file" } } \ No newline at end of file diff --git a/assets/language/fr.json b/assets/language/fr.json index c54cb8a..3815dd9 100644 --- a/assets/language/fr.json +++ b/assets/language/fr.json @@ -96,6 +96,10 @@ "CANNOT_FIND_TOOL": "Impossible de trouver l'outil", "IN_TOOLS_DIRECTORY": "dans le dossier des outils.", "CANNOT_EXTRACT_A_DIRECTORY": "Impossible d'extraire un dossier", - "CANNOT_FIND_SLOT": "Impossible de trouver le slot" + "CANNOT_FIND_SLOT": "Impossible de trouver le slot", + "FORBIDDEN_TRACKGROUP_ATTRIBUTE": "Attribut de groupe de course interdit", + "SAFE_EVAL_ERROR": "Erreur lors d'un safe eval", + "TEMPLATE_USED": "Modèle utilisé", + "MORE_IN_ERROR_LOG": "Plus d'information dans le fichier error.log" } } \ No newline at end of file diff --git a/source/gui/__init__.py b/source/gui/__init__.py index a8f6691..7f38bd2 100644 --- a/source/gui/__init__.py +++ b/source/gui/__init__.py @@ -25,6 +25,12 @@ def better_gui_error(func: Callable) -> Callable: f"{exc}\n" f"\n" ) - messagebox.showerror(_("Error"), exc) + + exc_split = exc.splitlines() + if len(exc_split) > 10: + # if the traceback is too long, only keep the 5 first and 5 last lines of the traceback + exc_split = exc_split[:5] + ["..."] + exc_split[-5:] + ["", "", _("MORE_IN_ERROR_LOG")] + + messagebox.showerror(_("Error"), "\n".join(exc_split)) return wrapper