mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
Added helper method to return unified information on create error
This commit is contained in:
parent
15d7a7589f
commit
b148dec048
1 changed files with 41 additions and 29 deletions
|
|
@ -1538,6 +1538,44 @@ class CreateContext:
|
|||
pre_create_data
|
||||
)
|
||||
|
||||
def _create_with_unified_error(
|
||||
self, identifier, creator, *args, **kwargs
|
||||
):
|
||||
error_message = "Failed to run Creator with identifier \"{}\". {}"
|
||||
|
||||
label = None
|
||||
add_traceback = False
|
||||
result = None
|
||||
fail_info = None
|
||||
success = False
|
||||
|
||||
try:
|
||||
# Try to get creator and his label
|
||||
if creator is None:
|
||||
creator = self._get_creator_in_create(identifier)
|
||||
label = getattr(creator, "label", label)
|
||||
|
||||
# Run create
|
||||
result = creator.create(*args, **kwargs)
|
||||
success = True
|
||||
|
||||
except CreatorError:
|
||||
exc_info = sys.exc_info()
|
||||
self.log.warning(error_message.format(identifier, exc_info[1]))
|
||||
|
||||
except:
|
||||
add_traceback = True
|
||||
exc_info = sys.exc_info()
|
||||
self.log.warning(
|
||||
error_message.format(identifier, ""),
|
||||
exc_info=True
|
||||
)
|
||||
|
||||
if not success:
|
||||
fail_info = prepare_failed_creator_operation_info(
|
||||
identifier, label, exc_info, add_traceback
|
||||
)
|
||||
return result, fail_info
|
||||
def creator_removed_instance(self, instance):
|
||||
"""When creator removes instance context should be acknowledged.
|
||||
|
||||
|
|
@ -1663,37 +1701,11 @@ class CreateContext:
|
|||
Reset instances if any autocreator executed properly.
|
||||
"""
|
||||
|
||||
error_message = "Failed to run AutoCreator with identifier \"{}\". {}"
|
||||
failed_info = []
|
||||
for identifier, creator in self.autocreators.items():
|
||||
label = creator.label
|
||||
failed = False
|
||||
add_traceback = False
|
||||
try:
|
||||
creator.create()
|
||||
|
||||
except CreatorError:
|
||||
failed = True
|
||||
exc_info = sys.exc_info()
|
||||
self.log.warning(error_message.format(identifier, exc_info[1]))
|
||||
|
||||
# Use bare except because some hosts raise their exceptions that
|
||||
# do not inherit from python's `BaseException`
|
||||
except:
|
||||
failed = True
|
||||
add_traceback = True
|
||||
exc_info = sys.exc_info()
|
||||
self.log.warning(
|
||||
error_message.format(identifier, ""),
|
||||
exc_info=True
|
||||
)
|
||||
|
||||
if failed:
|
||||
failed_info.append(
|
||||
prepare_failed_creator_operation_info(
|
||||
identifier, label, exc_info, add_traceback
|
||||
)
|
||||
)
|
||||
_, fail_info = self._create_with_unified_error(identifier, creator)
|
||||
if fail_info is not None:
|
||||
failed_info.append(fail_info)
|
||||
|
||||
if failed_info:
|
||||
raise CreatorsCreateFailed(failed_info)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue