From 2322d0f2ad1a88e00ae3febf4e16ba8d1ea6d90c Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 18 Jun 2024 12:01:51 +0200 Subject: [PATCH 1/3] safe access to shortName on folder type --- client/ayon_core/tools/common_models/projects.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/tools/common_models/projects.py b/client/ayon_core/tools/common_models/projects.py index 90b75e15c1..4e8925388d 100644 --- a/client/ayon_core/tools/common_models/projects.py +++ b/client/ayon_core/tools/common_models/projects.py @@ -89,7 +89,7 @@ def from_data(cls, data): def from_project_item(cls, folder_type_data): return cls( name=folder_type_data["name"], - short=folder_type_data["shortName"], + short=folder_type_data.get("shortName", ""), icon=folder_type_data["icon"], ) From 59e49182be07bc5758349165cc07d18ae87c10f4 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 18 Jun 2024 12:02:22 +0200 Subject: [PATCH 2/3] capture errors and add basic handle of the crash --- .../ayon_core/tools/utils/folders_widget.py | 6 ++++- client/ayon_core/tools/utils/lib.py | 22 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/client/ayon_core/tools/utils/folders_widget.py b/client/ayon_core/tools/utils/folders_widget.py index 3b53266c9f..bb75f3b6e5 100644 --- a/client/ayon_core/tools/utils/folders_widget.py +++ b/client/ayon_core/tools/utils/folders_widget.py @@ -192,7 +192,11 @@ def _on_refresh_thread(self, thread_id): or thread_id != self._current_refresh_thread.id ): return - folder_items, folder_type_items = thread.get_result() + if thread.failed: + # TODO visualize that refresh failed + folder_items, folder_type_items = {}, {} + else: + folder_items, folder_type_items = thread.get_result() self._fill_items(folder_items, folder_type_items) self._current_refresh_thread = None diff --git a/client/ayon_core/tools/utils/lib.py b/client/ayon_core/tools/utils/lib.py index e0626ec1db..5a7feb05eb 100644 --- a/client/ayon_core/tools/utils/lib.py +++ b/client/ayon_core/tools/utils/lib.py @@ -2,7 +2,10 @@ import sys import contextlib import collections +import traceback from functools import partial +from typing import Union, Any + from qtpy import QtWidgets, QtCore, QtGui import qtawesome @@ -425,26 +428,39 @@ def __init__(self, thread_id, func, *args, **kwargs): self._id = thread_id self._callback = partial(func, *args, **kwargs) self._exception = None + self._traceback = None self._result = None self.finished.connect(self._on_finish_callback) @property - def id(self): + def id(self) -> str: return self._id @property - def failed(self): + def failed(self) -> bool: return self._exception is not None def run(self): try: self._result = self._callback() except Exception as exc: + exc_type, exc_value, exc_traceback = sys.exc_info() + err_traceback = "".join(traceback.format_exception( + exc_type, exc_value, exc_traceback + )) + print(err_traceback) + self._traceback = err_traceback self._exception = exc - def get_result(self): + def get_result(self) -> Any: return self._result + def get_exception(self) -> Union[BaseException, None]: + return self._exception + + def get_traceback(self) -> Union[str, None]: + return self._traceback + def _on_finish_callback(self): """Trigger custom signal with thread id. From 9d8a8a98918ac125d583cf789ce50340e938e371 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 18 Jun 2024 12:12:03 +0200 Subject: [PATCH 3/3] remove unnecessary line --- client/ayon_core/tools/utils/lib.py | 1 - 1 file changed, 1 deletion(-) diff --git a/client/ayon_core/tools/utils/lib.py b/client/ayon_core/tools/utils/lib.py index 5a7feb05eb..f31bb82e59 100644 --- a/client/ayon_core/tools/utils/lib.py +++ b/client/ayon_core/tools/utils/lib.py @@ -6,7 +6,6 @@ from functools import partial from typing import Union, Any - from qtpy import QtWidgets, QtCore, QtGui import qtawesome import qtmaterialsymbols