diff --git a/src/credentials/FabricTable.cpp b/src/credentials/FabricTable.cpp index d9c0fcd345efd7..06dbf17cdb8dd2 100644 --- a/src/credentials/FabricTable.cpp +++ b/src/credentials/FabricTable.cpp @@ -601,10 +601,17 @@ CHIP_ERROR FabricTable::Delete(FabricIndex index) bool fabricIsInitialized = fabric != nullptr && fabric->IsInitialized(); CompressedFabricId compressedFabricId = fabricIsInitialized ? fabric->GetPeerId().GetCompressedFabricId() : kUndefinedCompressedFabricId; - ReturnErrorOnFailure(FabricInfo::DeleteFromStorage(mStorage, index)); // Delete from storage regardless + CHIP_ERROR err = FabricInfo::DeleteFromStorage(mStorage, index); // Delete from storage regardless + if (!fabricIsInitialized) + { + // Make sure to return the error our API promises, not whatever storage + // chose to return. + return CHIP_ERROR_NOT_FOUND; + } + ReturnErrorOnFailure(err); ReleaseFabricIndex(index); - if (mDelegate != nullptr && fabricIsInitialized) + if (mDelegate != nullptr) { if (mFabricCount == 0) { @@ -622,10 +629,6 @@ CHIP_ERROR FabricTable::Delete(FabricIndex index) delegate = delegate->mNext; } } - if (!fabricIsInitialized) - { - return CHIP_ERROR_NOT_FOUND; - } return CHIP_NO_ERROR; }