Skip to content

Commit

Permalink
fix the error dialog when asyncloader errors out
Browse files Browse the repository at this point in the history
  • Loading branch information
th3w1zard1 committed Aug 10, 2024
1 parent 03bfd62 commit b5420c6
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions Tools/HolocronToolset/src/toolset/gui/dialogs/asyncloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,23 @@ def _onSuccessful(self, result: Any):
self.optionalFinishHook.emit(result)

def _onFailed(self, error: Exception):
self.error = error
print("AsyncLoader._onFailed")
self.errors.append(error)
self.optionalErrorHook.emit(error)
RobustRootLogger().error(str(error), exc_info=error)
if len(self.errors) == 1: # Keep the first error as the main error
self.error = error

def _onCompleted(self, result: Any):
def _onCompleted(self):
print("_onCompleted")
if self.error is not None:
self.reject()
self._showErrorDialog()
else:
self.accept()

def _showErrorDialog(self):
print("AsyncLoader._showErrorDialog")
if self.errorTitle:
error_msgs = ""
for i, e in enumerate(self.errors):
Expand Down Expand Up @@ -262,10 +265,10 @@ def _onProgress(self, value: int | str, task_type: Literal["set_maximum", "incre


class AsyncWorker(QThread):
successful = QtCore.Signal(object)
failed = QtCore.Signal(object)
progress = QtCore.Signal(object, str)
completed = QtCore.Signal(object)
successful = QtCore.Signal(object) # pyright: ignore[reportPrivateImportUsage]
failed = QtCore.Signal(object) # pyright: ignore[reportPrivateImportUsage]
progress = QtCore.Signal(object, str) # pyright: ignore[reportPrivateImportUsage]
completed = QtCore.Signal() # pyright: ignore[reportPrivateImportUsage]

def __init__(
self,
Expand All @@ -287,18 +290,20 @@ def run(self):
profiler = cProfile.Profile()
profiler.enable()
result = None
for i, task in enumerate(self._tasks):
for task in self._tasks:
if len(self._tasks) > 1:
self.progress_callback(1, "increment")
try:
result = task()
except Exception as e: # pylint: disable=W0718 # noqa: BLE001
self.failed.emit(e)
if self._fast_fail:
print("fast fail, emit completed")
self.completed.emit()
break
else:
self.successful.emit(result)
self.completed.emit(result)
self.completed.emit()
if use_profiler:
profiler.disable()
profiler.dump_stats(f"{uuid.uuid1().hex[:7]}_async_worker.pstat")
Expand Down

0 comments on commit b5420c6

Please sign in to comment.