added error.log file when an error was occuring

This commit is contained in:
Faraphel 2022-07-25 21:07:22 +02:00
parent 5466a88c2d
commit d37ee5a79c
2 changed files with 8 additions and 1 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
/.idea/ /.idea/
/.cache/ /.cache/
/option.json /option.json
/error.log

View file

@ -1,7 +1,9 @@
import traceback import traceback
from pathlib import Path
from tkinter import messagebox from tkinter import messagebox
from typing import Callable from typing import Callable
from source.translation import translate as _ from source.translation import translate as _
import time
def better_gui_error(func: Callable) -> Callable: def better_gui_error(func: Callable) -> Callable:
@ -11,6 +13,10 @@ def better_gui_error(func: Callable) -> Callable:
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
try: return func(*args, **kwargs) try: return func(*args, **kwargs)
except: messagebox.showerror(_("Error"), traceback.format_exc()) except:
exc = traceback.format_exc()
with Path("error.log").open("a", encoding="utf8") as log_file:
log_file.write(f"{'#' * 20}\n{time.strftime('%Y/%M/%d %H:%m:%S')}\n\n{exc}\n\n")
messagebox.showerror(_("Error"), exc)
return wrapper return wrapper