From fa69cc102b297dc12727e7792fbddb60c46fe63b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 31 Aug 2022 16:22:34 +0200 Subject: [PATCH] Add-on: clearer error message when job compiler refuses the job Blender now shows the actual returned error from the Manager when job submission fails, rather than a generic "failed" message. --- addon/flamenco/operators.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/addon/flamenco/operators.py b/addon/flamenco/operators.py index a0916f1b..49f1861f 100644 --- a/addon/flamenco/operators.py +++ b/addon/flamenco/operators.py @@ -18,11 +18,19 @@ if TYPE_CHECKING: PackThread as _PackThread, Message as _Message, ) - from .manager.models import SubmittedJob as _SubmittedJob + from .manager.models import ( + Error as _Error, + SubmittedJob as _SubmittedJob, + ) + from .manager.api_client import ApiClient as _ApiClient + from .manager.exceptions import ApiException as _ApiException else: _PackThread = object _Message = object _SubmittedJob = object + _ApiClient = object + _ApiException = object + _Error = object _log = logging.getLogger(__name__) @@ -440,6 +448,10 @@ class FLAMENCO_OT_submit_job(FlamencoOpMixin, bpy.types.Operator): "Cached job type is old. Refresh the job types and submit again, please", ) return + if ex.status == 400: + error = parse_api_error(api_client, ex) + self.report({"ERROR"}, error.message) + return self.report({"ERROR"}, f"Could not submit job: {ex.reason}") return @@ -518,3 +530,18 @@ classes = ( FLAMENCO3_OT_explore_file_path, ) register, unregister = bpy.utils.register_classes_factory(classes) + + +def parse_api_error(api_client: _ApiClient, ex: _ApiException) -> _Error: + """Parse the body of an ApiException into an manager.models.Error instance.""" + + from .manager.models import Error + + class MockResponse: + data: str + + response = MockResponse() + response.data = ex.body + + error: _Error = api_client.deserialize(response, (Error, ), True) + return error