controller has new method 'get_error_info'

This commit is contained in:
Jakub Trllo 2024-09-02 13:35:19 +02:00
parent 83befb24a4
commit 050f816ce4
5 changed files with 53 additions and 27 deletions

View file

@ -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

View file

@ -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()

View file

@ -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",
)

View file

@ -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

View file

@ -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)