From 050f816ce4cca5c314c8cb19bf2e3af8088f34d7 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 2 Sep 2024 13:35:19 +0200 Subject: [PATCH] controller has new method 'get_error_info' --- client/ayon_core/tools/publisher/abstract.py | 9 ++- client/ayon_core/tools/publisher/control.py | 4 +- .../tools/publisher/models/__init__.py | 3 +- .../tools/publisher/models/publish.py | 58 ++++++++++++++----- .../tools/publisher/widgets/publish_frame.py | 6 +- 5 files changed, 53 insertions(+), 27 deletions(-) diff --git a/client/ayon_core/tools/publisher/abstract.py b/client/ayon_core/tools/publisher/abstract.py index 362fa38882..78f7756c96 100644 --- a/client/ayon_core/tools/publisher/abstract.py +++ b/client/ayon_core/tools/publisher/abstract.py @@ -26,7 +26,7 @@ from ayon_core.tools.common_models import ( ) if TYPE_CHECKING: - from .models import CreatorItem + from .models import CreatorItem, PublishErrorInfo class CardMessageTypes: @@ -537,14 +537,13 @@ class AbstractPublisherFrontend(AbstractPublisherCommon): pass @abstractmethod - def get_publish_error_msg(self) -> Union[str, None]: + def get_publish_error_info(self) -> Union["PublishErrorInfo", None]: """Current error message which cause fail of publishing. Returns: - Union[str, None]: Message which will be showed to artist or - None. - """ + Union[PublishErrorInfo, None]: Error info or None. + """ pass @abstractmethod diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index 257b45de08..5c76e01f0c 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -493,8 +493,8 @@ class PublisherController( def get_publish_progress(self): return self._publish_model.get_progress() - def get_publish_error_msg(self): - return self._publish_model.get_error_msg() + def get_publish_error_info(self): + return self._publish_model.get_error_info() def get_publish_report(self): return self._publish_model.get_publish_report() diff --git a/client/ayon_core/tools/publisher/models/__init__.py b/client/ayon_core/tools/publisher/models/__init__.py index bd593be29b..07f061deaa 100644 --- a/client/ayon_core/tools/publisher/models/__init__.py +++ b/client/ayon_core/tools/publisher/models/__init__.py @@ -1,5 +1,5 @@ from .create import CreateModel, CreatorItem -from .publish import PublishModel +from .publish import PublishModel, PublishErrorInfo __all__ = ( @@ -7,4 +7,5 @@ __all__ = ( "CreatorItem", "PublishModel", + "PublishErrorInfo", ) diff --git a/client/ayon_core/tools/publisher/models/publish.py b/client/ayon_core/tools/publisher/models/publish.py index a60ef69fac..e15f4f6080 100644 --- a/client/ayon_core/tools/publisher/models/publish.py +++ b/client/ayon_core/tools/publisher/models/publish.py @@ -23,6 +23,40 @@ PUBLISH_EVENT_SOURCE = "publisher.publish.model" PLUGIN_ORDER_OFFSET = 0.5 +class PublishErrorInfo: + def __init__(self, description, title, detail): + self.description = description + self.title = title + self.detail = detail + + def __eq__(self, other): + if not isinstance(other, PublishErrorInfo): + return False + return ( + self.description == other.description + and self.title == other.title + and self.detail == other.detail + ) + + def __ne__(self, other): + return not self.__eq__(other) + + @classmethod + def from_exception(cls, exc): + title = "This is not your fault" + detail = ( + "Please report the error to your pipeline support" + " using one of the options below." + ) + if isinstance(exc, KnownPublishError): + msg = str(exc) + else: + msg = ( + "Something went wrong. Send report" + " to your supervisor or Ynput team." + ) + return cls(msg, title, detail) + class PublishReportMaker: """Report for single publishing process. @@ -801,7 +835,7 @@ class PublishModel: self._publish_comment_is_set: bool = False # Any other exception that happened during publishing - self._publish_error_msg: Optional[str] = None + self._publish_error_info: Optional[PublishErrorInfo] = None # Publishing is in progress self._publish_is_running: bool = False # Publishing is over validation order @@ -851,7 +885,7 @@ class PublishModel: self._publish_comment_is_set = False self._publish_has_started = False - self._set_publish_error_msg(None) + self._set_publish_error_info(None) self._set_progress(0) self._set_is_running(False) self._set_has_validated(False) @@ -977,8 +1011,8 @@ class PublishModel: def get_validation_errors(self) -> PublishValidationErrorsReport: return self._publish_validation_errors.create_report() - def get_error_msg(self) -> Optional[str]: - return self._publish_error_msg + def get_error_info(self) -> Optional[PublishErrorInfo]: + return self._publish_error_info def set_comment(self, comment: str): # Ignore change of comment when publishing started @@ -1077,9 +1111,9 @@ class PublishModel: {"value": value} ) - def _set_publish_error_msg(self, value: Optional[str]): - if self._publish_error_msg != value: - self._publish_error_msg = value + def _set_publish_error_info(self, value: Optional[PublishErrorInfo]): + if self._publish_error_info != value: + self._publish_error_info = value self._emit_event( "publish.publish_error.changed", {"value": value} @@ -1234,14 +1268,8 @@ class PublishModel: self._add_validation_error(result) else: - if isinstance(exception, KnownPublishError): - msg = str(exception) - else: - msg = ( - "Something went wrong. Send report" - " to your supervisor or Ynput team." - ) - self._set_publish_error_msg(msg) + error_info = PublishErrorInfo.from_exception(exception) + self._set_publish_error_info(error_info) self._set_is_crashed(True) result["is_validation_error"] = has_validation_error diff --git a/client/ayon_core/tools/publisher/widgets/publish_frame.py b/client/ayon_core/tools/publisher/widgets/publish_frame.py index 6eaeb6daf2..d9a9e501ef 100644 --- a/client/ayon_core/tools/publisher/widgets/publish_frame.py +++ b/client/ayon_core/tools/publisher/widgets/publish_frame.py @@ -411,10 +411,8 @@ class PublishFrame(QtWidgets.QWidget): """Show error message to artist on publish crash.""" self._set_main_label("Error happened") - - self._message_label_top.setText( - self._controller.get_publish_error_msg() - ) + error_info = self._controller.get_publish_error_info() + self._message_label_top.setText(error_info.description) self._set_success_property(1)