From a7624bb98587372350549fe15c1c63250b4434ac Mon Sep 17 00:00:00 2001 From: srikappa Date: Mon, 3 May 2021 17:23:00 -0700 Subject: [PATCH] Removed returning AZ::Failure when AZ::Assert is thrown --- .../Prefab/PrefabPublicHandler.cpp | 57 ++++++------------- .../Prefab/PrefabPublicHandler.h | 3 +- 2 files changed, 17 insertions(+), 43 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp index 1b4bf9f50c..475510c52f 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp @@ -96,12 +96,7 @@ namespace AzToolsFramework // target templates of the other instances. for (auto& nestedInstance : instances) { - PrefabOperationResult removeLinkResult = RemoveLink( - nestedInstance, commonRootEntityOwningInstance->get().GetTemplateId(), undoBatch.GetUndoBatch()); - if (!removeLinkResult.IsSuccess()) - { - return removeLinkResult; - } + RemoveLink(nestedInstance, commonRootEntityOwningInstance->get().GetTemplateId(), undoBatch.GetUndoBatch()); } PrefabUndoHelpers::UpdatePrefabInstance( @@ -241,14 +236,9 @@ namespace AzToolsFramework // Retrieve the owning instance of the common root entity, which will be our new instance's parent instance. commonRootEntityOwningInstance = GetOwnerInstanceByEntityId(commonRootEntityId); - if (!commonRootEntityOwningInstance) - { - AZ_Assert( - false, - "Failed to create prefab : Couldn't get a valid owning instance for the common root entity of the enities provided"); - return AZ::Failure(AZStd::string( - "Failed to create prefab : Couldn't get a valid owning instance for the common root entity of the enities provided")); - } + AZ_Assert( + commonRootEntityOwningInstance.has_value(), + "Failed to create prefab : Couldn't get a valid owning instance for the common root entity of the enities provided"); return AZ::Success(); } @@ -290,47 +280,32 @@ namespace AzToolsFramework m_prefabUndoCache.Store(containerEntityId, AZStd::move(containerEntityDomAfter)); } - PrefabOperationResult PrefabPublicHandler::RemoveLink( + void PrefabPublicHandler::RemoveLink( AZStd::unique_ptr& sourceInstance, TemplateId targetTemplateId, UndoSystem::URSequencePoint* undoBatch) { LinkReference nestedInstanceLink = m_prefabSystemComponentInterface->FindLink(sourceInstance->GetLinkId()); - if (!nestedInstanceLink.has_value()) - { - AZ_Assert(false, "A valid link was not found for one of the instances provided as input for the CreatePrefab operation."); - return AZ::Failure( - AZStd::string("A valid link was not found for one of the instances provided as input for the CreatePrefab operation.")); - } + AZ_Assert( + nestedInstanceLink.has_value(), + "A valid link was not found for one of the instances provided as input for the CreatePrefab operation."); PrefabDomReference nestedInstanceLinkDom = nestedInstanceLink->get().GetLinkDom(); - if (!nestedInstanceLinkDom.has_value()) - { - AZ_Assert( - false, - "A valid DOM was not found for the link corresponding to one of the instances provided as input for the " - "CreatePrefab operation."); - return AZ::Failure(AZStd::string("A valid DOM was not found for the link corresponding to one of the instances " - "provided as input for the CreatePrefab operation.")); - } + AZ_Assert( + nestedInstanceLinkDom.has_value(), + "A valid DOM was not found for the link corresponding to one of the instances provided as input for the " + "CreatePrefab operation."); PrefabDomValueReference nestedInstanceLinkPatches = PrefabDomUtils::FindPrefabDomValue(nestedInstanceLinkDom->get(), PrefabDomUtils::PatchesName); - if (!nestedInstanceLinkPatches.has_value()) - { - AZ_Assert( - false, - "A valid DOM for patches was not found for the link corresponding to one of the instances provided as input for the " - "CreatePrefab operation."); - return AZ::Failure(AZStd::string("A valid DOM for patcheswas not found for the link corresponding to one of the instances " - "provided as input for the CreatePrefab operation.")); - } + AZ_Assert( + nestedInstanceLinkPatches.has_value(), + "A valid DOM for patches was not found for the link corresponding to one of the instances provided as input for the " + "CreatePrefab operation."); PrefabDom patchesCopyForUndoSupport; patchesCopyForUndoSupport.CopyFrom(nestedInstanceLinkPatches->get(), patchesCopyForUndoSupport.GetAllocator()); PrefabUndoHelpers::RemoveLink( sourceInstance->GetTemplateId(), targetTemplateId, sourceInstance->GetInstanceAlias(), sourceInstance->GetLinkId(), patchesCopyForUndoSupport, undoBatch); - - return AZ::Success(); } PrefabOperationResult PrefabPublicHandler::SavePrefab(AZ::IO::Path filePath) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h index 8d27603e8d..5ade666a40 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h @@ -88,9 +88,8 @@ namespace AzToolsFramework * \param sourceInstance The instance corresponding to the source template of the link to be removed. * \param targetTemplateId The id of the target template of the link to be removed. * \param undoBatch The undo batch to set as parent for this remove link action. - * \return PrefabOperationResult Indicates whether the removal of link was successful. */ - PrefabOperationResult RemoveLink( + void RemoveLink( AZStd::unique_ptr& sourceInstance, TemplateId targetTemplateId, UndoSystem::URSequencePoint* undoBatch); /**