Skip to content

Commit 0060e0e

Browse files
Replace ReturnErrorCodeIf with VerifyOrReturnError (#36083)
* 'ReturnErrorCodeIf(!$A, $B);' -> 'VerifyOrReturnError($A, $B);' * 'ReturnErrorCodeIf($A == $B, $C);' -> 'VerifyOrReturnError($A != $B, $C);' * 'ReturnErrorCodeIf($A != $B, $C);' -> 'VerifyOrReturnError($A == $B, $C);' * 'ReturnErrorCodeIf($A < $B, $C);' -> 'VerifyOrReturnError($A >= $B, $C);' * 'ReturnErrorCodeIf($A <= $B, $C);' -> 'VerifyOrReturnError($A > $B, $C);' * 'ReturnErrorCodeIf($A > $B, $C);' -> 'VerifyOrReturnError($A <= $B, $C);' * 'ReturnErrorCodeIf($A >= $B, $C);' -> 'VerifyOrReturnError($A < $B, $C);' * 'ReturnErrorCodeIf($A($$$B), $C);' -> 'VerifyOrReturnError(!$A($$$B), $C);' * 'ReturnErrorCodeIf($A, $B);' -> 'VerifyOrReturnError(!$A, $B);' * Replace ReturnErrorCodeWithMetricIf with VerifyOrReturnErrorWithMetric * Restyled by clang-format * 'ReturnErrorCodeIf($A != $B && $C != $D, $Z);' --rewrite 'VerifyOrReturnError($A == $B || $C == $D, $Z);' * 'ReturnErrorCodeIf($A == $B && $C == $D, $Z);' --rewrite 'VerifyOrReturnError($A != $B || $C != $D, $Z);' * 'ReturnErrorCodeIf($A == $B || $C == $D, $Z);' --rewrite 'VerifyOrReturnError($A != $B && $C != $D, $Z);' * 'ReturnErrorCodeIf($A || $B, $Z);' --rewrite 'VerifyOrReturnError(!($A) && !($B), $Z);' This commit was manually optimized. * 'ReturnErrorCodeIf($A && $B, $Z);' --rewrite 'VerifyOrReturnError(!($A) || !($B), $Z);' This commit was manually optimized. * Drop support for ReturnErrorCodeIf * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent edf3b8b commit 0060e0e

File tree

160 files changed

+695
-782
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+695
-782
lines changed

examples/bridge-app/asr/subdevice/SubDeviceManager.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ Protocols::InteractionModel::Status HandleWriteOnOffAttribute(SubDevice * dev, c
156156
{
157157
ChipLogProgress(DeviceLayer, "HandleWriteOnOffAttribute: attrId=%" PRIu32, attributeId);
158158

159-
ReturnErrorCodeIf((attributeId != OnOff::Attributes::OnOff::Id) || (!dev->IsReachable()),
160-
Protocols::InteractionModel::Status::Failure);
159+
VerifyOrReturnError((attributeId == OnOff::Attributes::OnOff::Id) && dev->IsReachable(),
160+
Protocols::InteractionModel::Status::Failure);
161161
dev->SetOnOff(*buffer == 1);
162162
return Protocols::InteractionModel::Status::Success;
163163
}

examples/bridge-app/esp32/main/main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ Protocols::InteractionModel::Status HandleWriteOnOffAttribute(Device * dev, chip
268268
{
269269
ChipLogProgress(DeviceLayer, "HandleWriteOnOffAttribute: attrId=%" PRIu32, attributeId);
270270

271-
ReturnErrorCodeIf((attributeId != OnOff::Attributes::OnOff::Id) || (!dev->IsReachable()),
272-
Protocols::InteractionModel::Status::Failure);
271+
VerifyOrReturnError((attributeId == OnOff::Attributes::OnOff::Id) && dev->IsReachable(),
272+
Protocols::InteractionModel::Status::Failure);
273273
dev->SetOnOff(*buffer == 1);
274274
return Protocols::InteractionModel::Status::Success;
275275
}

examples/bridge-app/telink/src/AppTask.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ Protocols::InteractionModel::Status HandleWriteOnOffAttribute(Device * dev, chip
298298
{
299299
ChipLogProgress(DeviceLayer, "HandleWriteOnOffAttribute: attrId=%" PRIu32, attributeId);
300300

301-
ReturnErrorCodeIf((attributeId != Clusters::OnOff::Attributes::OnOff::Id) || (!dev->IsReachable()),
302-
Protocols::InteractionModel::Status::Failure);
301+
VerifyOrReturnError((attributeId == Clusters::OnOff::Attributes::OnOff::Id) && dev->IsReachable(),
302+
Protocols::InteractionModel::Status::Failure);
303303
dev->SetOnOff(*buffer == 1);
304304
return Protocols::InteractionModel::Status::Success;
305305
}

examples/chip-tool/commands/delay/WaitForCommissioneeCommand.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ using namespace chip;
2323
CHIP_ERROR WaitForCommissioneeCommand::RunCommand()
2424
{
2525
chip::FabricIndex fabricIndex = CurrentCommissioner().GetFabricIndex();
26-
ReturnErrorCodeIf(fabricIndex == chip::kUndefinedFabricIndex, CHIP_ERROR_INCORRECT_STATE);
26+
VerifyOrReturnError(fabricIndex != chip::kUndefinedFabricIndex, CHIP_ERROR_INCORRECT_STATE);
2727

2828
if (mExpireExistingSession.ValueOr(true))
2929
{

examples/energy-management-app/energy-management-common/energy-evse/src/EnergyEvseTargetsStore.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ CHIP_ERROR EvseTargetsDelegate::LoadTargets()
7575

7676
Platform::ScopedMemoryBuffer<uint8_t> backingBuffer;
7777
uint16_t length = GetTlvSizeUpperBound();
78-
ReturnErrorCodeIf(!backingBuffer.Calloc(length), CHIP_ERROR_NO_MEMORY);
78+
VerifyOrReturnError(backingBuffer.Calloc(length), CHIP_ERROR_NO_MEMORY);
7979

8080
CHIP_ERROR err = mpTargetStore->SyncGetKeyValue(spEvseTargetsKeyName, backingBuffer.Get(), length);
8181
if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
@@ -390,7 +390,7 @@ EvseTargetsDelegate::SaveTargets(DataModel::List<const Structs::ChargingTargetSc
390390
uint16_t total = GetTlvSizeUpperBound();
391391

392392
Platform::ScopedMemoryBuffer<uint8_t> backingBuffer;
393-
ReturnErrorCodeIf(!backingBuffer.Calloc(total), CHIP_ERROR_NO_MEMORY);
393+
VerifyOrReturnError(backingBuffer.Calloc(total), CHIP_ERROR_NO_MEMORY);
394394
TLV::ScopedBufferTLVWriter writer(std::move(backingBuffer), total);
395395

396396
TLV::TLVType arrayType;

examples/persistent-storage/KeyValueStorageTest.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ CHIP_ERROR TestEmptyString()
5555
size_t read_size;
5656
ReturnErrorOnFailure(KeyValueStoreMgr().Put(kTestKey, kTestValue));
5757
ReturnErrorOnFailure(KeyValueStoreMgr().Get(kTestKey, read_value, sizeof(read_value), &read_size));
58-
ReturnErrorCodeIf(strcmp(kTestValue, read_value) != 0, CHIP_ERROR_INTERNAL);
59-
ReturnErrorCodeIf(read_size != sizeof(kTestValue), CHIP_ERROR_INTERNAL);
58+
VerifyOrReturnError(strcmp(kTestValue, read_value) == 0, CHIP_ERROR_INTERNAL);
59+
VerifyOrReturnError(read_size == sizeof(kTestValue), CHIP_ERROR_INTERNAL);
6060
ReturnErrorOnFailure(KeyValueStoreMgr().Delete(kTestKey));
6161
return CHIP_NO_ERROR;
6262
}
@@ -69,8 +69,8 @@ CHIP_ERROR TestString()
6969
size_t read_size;
7070
ReturnErrorOnFailure(KeyValueStoreMgr().Put(kTestKey, kTestValue));
7171
ReturnErrorOnFailure(KeyValueStoreMgr().Get(kTestKey, read_value, sizeof(read_value), &read_size));
72-
ReturnErrorCodeIf(strcmp(kTestValue, read_value) != 0, CHIP_ERROR_INTERNAL);
73-
ReturnErrorCodeIf(read_size != sizeof(kTestValue), CHIP_ERROR_INTERNAL);
72+
VerifyOrReturnError(strcmp(kTestValue, read_value) == 0, CHIP_ERROR_INTERNAL);
73+
VerifyOrReturnError(read_size == sizeof(kTestValue), CHIP_ERROR_INTERNAL);
7474
ReturnErrorOnFailure(KeyValueStoreMgr().Delete(kTestKey));
7575
return CHIP_NO_ERROR;
7676
}
@@ -82,7 +82,7 @@ CHIP_ERROR TestUint32()
8282
uint32_t read_value;
8383
ReturnErrorOnFailure(KeyValueStoreMgr().Put(kTestKey, kTestValue));
8484
ReturnErrorOnFailure(KeyValueStoreMgr().Get(kTestKey, &read_value));
85-
ReturnErrorCodeIf(kTestValue != read_value, CHIP_ERROR_INTERNAL);
85+
VerifyOrReturnError(kTestValue == read_value, CHIP_ERROR_INTERNAL);
8686
ReturnErrorOnFailure(KeyValueStoreMgr().Delete(kTestKey));
8787
return CHIP_NO_ERROR;
8888
}
@@ -94,7 +94,7 @@ CHIP_ERROR TestArray()
9494
uint32_t read_value[5];
9595
ReturnErrorOnFailure(KeyValueStoreMgr().Put(kTestKey, kTestValue));
9696
ReturnErrorOnFailure(KeyValueStoreMgr().Get(kTestKey, &read_value));
97-
ReturnErrorCodeIf(memcmp(kTestValue, read_value, sizeof(kTestValue)) != 0, CHIP_ERROR_INTERNAL);
97+
VerifyOrReturnError(memcmp(kTestValue, read_value, sizeof(kTestValue)) == 0, CHIP_ERROR_INTERNAL);
9898
ReturnErrorOnFailure(KeyValueStoreMgr().Delete(kTestKey));
9999
return CHIP_NO_ERROR;
100100
}
@@ -111,8 +111,8 @@ CHIP_ERROR TestStruct()
111111
SomeStruct read_value;
112112
ReturnErrorOnFailure(KeyValueStoreMgr().Put(kTestKey, kTestValue));
113113
ReturnErrorOnFailure(KeyValueStoreMgr().Get(kTestKey, &read_value));
114-
ReturnErrorCodeIf(kTestValue.value1 != read_value.value1, CHIP_ERROR_INTERNAL);
115-
ReturnErrorCodeIf(kTestValue.value2 != read_value.value2, CHIP_ERROR_INTERNAL);
114+
VerifyOrReturnError(kTestValue.value1 == read_value.value1, CHIP_ERROR_INTERNAL);
115+
VerifyOrReturnError(kTestValue.value2 == read_value.value2, CHIP_ERROR_INTERNAL);
116116
ReturnErrorOnFailure(KeyValueStoreMgr().Delete(kTestKey));
117117
return CHIP_NO_ERROR;
118118
}
@@ -125,7 +125,7 @@ CHIP_ERROR TestUpdateValue()
125125
{
126126
ReturnErrorOnFailure(KeyValueStoreMgr().Put(kTestKey, i));
127127
ReturnErrorOnFailure(KeyValueStoreMgr().Get(kTestKey, &read_value));
128-
ReturnErrorCodeIf(i != read_value, CHIP_ERROR_INTERNAL);
128+
VerifyOrReturnError(i == read_value, CHIP_ERROR_INTERNAL);
129129
}
130130
ReturnErrorOnFailure(KeyValueStoreMgr().Delete(kTestKey));
131131
return CHIP_NO_ERROR;
@@ -142,9 +142,9 @@ CHIP_ERROR TestMultiRead()
142142
size_t read_size;
143143
// Returns buffer too small for all but the last read.
144144
CHIP_ERROR error = KeyValueStoreMgr().Get(kTestKey, &read_value, sizeof(read_value), &read_size, i * sizeof(uint32_t));
145-
ReturnErrorCodeIf(error != (i < 4 ? CHIP_ERROR_BUFFER_TOO_SMALL : CHIP_NO_ERROR), error);
146-
ReturnErrorCodeIf(read_size != sizeof(read_value), CHIP_ERROR_INTERNAL);
147-
ReturnErrorCodeIf(kTestValue[i] != read_value, CHIP_ERROR_INTERNAL);
145+
VerifyOrReturnError(error == (i < 4 ? CHIP_ERROR_BUFFER_TOO_SMALL : CHIP_NO_ERROR), error);
146+
VerifyOrReturnError(read_size == sizeof(read_value), CHIP_ERROR_INTERNAL);
147+
VerifyOrReturnError(kTestValue[i] == read_value, CHIP_ERROR_INTERNAL);
148148
}
149149
ReturnErrorOnFailure(KeyValueStoreMgr().Delete(kTestKey));
150150
return CHIP_NO_ERROR;

examples/platform/cc13x4_26x4/CC13X4_26X4DeviceAttestationCreds.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,17 @@ CHIP_ERROR DeviceAttestationCredsCC13X4_26X4::GetFirmwareInformation(MutableByte
218218

219219
CHIP_ERROR DeviceAttestationCredsCC13X4_26X4::GetDeviceAttestationCert(MutableByteSpan & out_buffer)
220220
{
221-
ReturnErrorCodeIf(out_buffer.size() < mFactoryData->dac_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL);
222-
ReturnErrorCodeIf(!mFactoryData->dac_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);
221+
VerifyOrReturnError(out_buffer.size() >= mFactoryData->dac_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL);
222+
VerifyOrReturnError(mFactoryData->dac_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);
223223

224224
return CopySpanToMutableSpan(ByteSpan{ mFactoryData->dac_cert.data, mFactoryData->dac_cert.len }, out_buffer);
225225
return CHIP_NO_ERROR;
226226
}
227227

228228
CHIP_ERROR DeviceAttestationCredsCC13X4_26X4::GetProductAttestationIntermediateCert(MutableByteSpan & out_buffer)
229229
{
230-
ReturnErrorCodeIf(out_buffer.size() < mFactoryData->pai_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL);
231-
ReturnErrorCodeIf(!mFactoryData->pai_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);
230+
VerifyOrReturnError(out_buffer.size() >= mFactoryData->pai_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL);
231+
VerifyOrReturnError(mFactoryData->pai_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);
232232

233233
return CopySpanToMutableSpan(ByteSpan{ mFactoryData->pai_cert.data, mFactoryData->pai_cert.len }, out_buffer);
234234
}

examples/platform/cc32xx/CC32XXDeviceAttestationCreds.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -349,17 +349,17 @@ CHIP_ERROR DeviceAttestationCredsCC32XX::GetFirmwareInformation(MutableByteSpan
349349

350350
CHIP_ERROR DeviceAttestationCredsCC32XX::GetDeviceAttestationCert(MutableByteSpan & out_buffer)
351351
{
352-
ReturnErrorCodeIf(out_buffer.size() < mFactoryData->dac_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL);
353-
ReturnErrorCodeIf(!mFactoryData->dac_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);
352+
VerifyOrReturnError(out_buffer.size() >= mFactoryData->dac_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL);
353+
VerifyOrReturnError(mFactoryData->dac_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);
354354

355355
return CopySpanToMutableSpan(ByteSpan{ mFactoryData->dac_cert.data, mFactoryData->dac_cert.len }, out_buffer);
356356
return CHIP_NO_ERROR;
357357
}
358358

359359
CHIP_ERROR DeviceAttestationCredsCC32XX::GetProductAttestationIntermediateCert(MutableByteSpan & out_buffer)
360360
{
361-
ReturnErrorCodeIf(out_buffer.size() < mFactoryData->pai_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL);
362-
ReturnErrorCodeIf(!mFactoryData->pai_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);
361+
VerifyOrReturnError(out_buffer.size() >= mFactoryData->pai_cert.len, CHIP_ERROR_BUFFER_TOO_SMALL);
362+
VerifyOrReturnError(mFactoryData->pai_cert.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);
363363

364364
return CopySpanToMutableSpan(ByteSpan{ mFactoryData->pai_cert.data, mFactoryData->pai_cert.len }, out_buffer);
365365
}

examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ static void wfx_rsi_save_ap_info(void) // translation
619619
**********************************************************************************************/
620620
static sl_status_t wfx_rsi_do_join(void)
621621
{
622-
ReturnErrorCodeIf((wfx_rsi.dev_state & (WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED)), SL_STATUS_IN_PROGRESS);
622+
VerifyOrReturnError(!(wfx_rsi.dev_state & (WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED)), SL_STATUS_IN_PROGRESS);
623623
sl_status_t status = SL_STATUS_OK;
624624
sl_wifi_client_configuration_t ap;
625625
memset(&ap, 0, sizeof(ap));
@@ -680,7 +680,7 @@ static sl_status_t wfx_rsi_do_join(void)
680680
status = sl_wifi_connect(SL_WIFI_CLIENT_INTERFACE, &ap, timeout_ms);
681681
// sl_wifi_connect returns SL_STATUS_IN_PROGRESS if join is in progress
682682
// after the initial scan is done, the scan does not check for SSID
683-
ReturnErrorCodeIf((status == SL_STATUS_OK || status == SL_STATUS_IN_PROGRESS), status);
683+
VerifyOrReturnError(status != SL_STATUS_OK && status != SL_STATUS_IN_PROGRESS, status);
684684

685685
// failure only happens when the firmware returns an error
686686
ChipLogError(DeviceLayer, "wfx_rsi_do_join: sl_wifi_connect failed: 0x%lx", static_cast<uint32_t>(status));

examples/platform/silabs/provision/ProvisionStorageFlash.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ CHIP_ERROR DecodeTotal(Encoding::Buffer & reader, uint16_t & total)
7878
ReturnErrorOnFailure(reader.Get(sz));
7979
total = (0xffff == sz) ? sizeof(uint16_t) : sz;
8080
reader.in = reader.begin + total;
81-
ReturnErrorCodeIf(reader.in > reader.end, CHIP_ERROR_INTERNAL);
81+
VerifyOrReturnError(reader.in <= reader.end, CHIP_ERROR_INTERNAL);
8282
return CHIP_NO_ERROR;
8383
}
8484

@@ -118,7 +118,7 @@ CHIP_ERROR Set(uint16_t id, Encoding::Buffer & in)
118118
{
119119
// New entry
120120
size_t temp_total = found.offset;
121-
ReturnErrorCodeIf(temp_total + in.Size() > kPageSize, CHIP_ERROR_INVALID_ARGUMENT);
121+
VerifyOrReturnError(temp_total + in.Size() <= kPageSize, CHIP_ERROR_INVALID_ARGUMENT);
122122
// Copy entry
123123
ReturnErrorOnFailure(in.Get(page + temp_total, in.Size()));
124124
// Update total
@@ -138,7 +138,7 @@ CHIP_ERROR Set(uint16_t id, Encoding::Buffer & in)
138138
{
139139
// Size change, move to the end
140140
uint16_t temp_total = total - found.encoded_size;
141-
ReturnErrorCodeIf(temp_total + in.Size() > kPageSize, CHIP_ERROR_INVALID_ARGUMENT);
141+
VerifyOrReturnError(temp_total + in.Size() <= kPageSize, CHIP_ERROR_INVALID_ARGUMENT);
142142
// Remove the entry
143143
memmove(page + found.offset, page + found.offset + found.encoded_size, temp_total);
144144
// Add the entry

examples/tv-casting-app/tv-casting-common/include/MediaCommandBase.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class MediaCommandBase : public MediaBase
3232
VerifyOrDieWithMsg(mTargetVideoPlayerInfo != nullptr, AppServer, "Target unknown");
3333

3434
auto deviceProxy = mTargetVideoPlayerInfo->GetOperationalDeviceProxy();
35-
ReturnErrorCodeIf(deviceProxy == nullptr || !deviceProxy->ConnectionReady(), CHIP_ERROR_PEER_NODE_NOT_FOUND);
35+
VerifyOrReturnError(deviceProxy != nullptr && deviceProxy->ConnectionReady(), CHIP_ERROR_PEER_NODE_NOT_FOUND);
3636

3737
sResponseCallback = responseCallback;
3838

examples/tv-casting-app/tv-casting-common/include/MediaReadBase.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class MediaReadBase : public MediaBase
3232
VerifyOrDieWithMsg(mTargetVideoPlayerInfo != nullptr, AppServer, "Target unknown");
3333

3434
auto deviceProxy = mTargetVideoPlayerInfo->GetOperationalDeviceProxy();
35-
ReturnErrorCodeIf(deviceProxy == nullptr || !deviceProxy->ConnectionReady(), CHIP_ERROR_PEER_NODE_NOT_FOUND);
35+
VerifyOrReturnError(deviceProxy != nullptr && deviceProxy->ConnectionReady(), CHIP_ERROR_PEER_NODE_NOT_FOUND);
3636

3737
MediaClusterBase cluster(*deviceProxy->GetExchangeManager(), deviceProxy->GetSecureSession().Value(), mTvEndpoint);
3838

examples/tv-casting-app/tv-casting-common/include/MediaSubscriptionBase.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class MediaSubscriptionBase : public MediaBase
3333
VerifyOrDieWithMsg(mTargetVideoPlayerInfo != nullptr, AppServer, "Target unknown");
3434

3535
auto deviceProxy = mTargetVideoPlayerInfo->GetOperationalDeviceProxy();
36-
ReturnErrorCodeIf(deviceProxy == nullptr || !deviceProxy->ConnectionReady(), CHIP_ERROR_PEER_NODE_NOT_FOUND);
36+
VerifyOrReturnError(deviceProxy != nullptr && deviceProxy->ConnectionReady(), CHIP_ERROR_PEER_NODE_NOT_FOUND);
3737

3838
MediaClusterBase cluster(*deviceProxy->GetExchangeManager(), deviceProxy->GetSecureSession().Value(), mTvEndpoint);
3939

src/access/AccessControl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ CHIP_ERROR AccessControl::CreateEntry(const SubjectDescriptor * subjectDescripto
232232

233233
VerifyOrReturnError((count + 1) <= maxCount, CHIP_ERROR_BUFFER_TOO_SMALL);
234234

235-
ReturnErrorCodeIf(!IsValid(entry), CHIP_ERROR_INVALID_ARGUMENT);
235+
VerifyOrReturnError(IsValid(entry), CHIP_ERROR_INVALID_ARGUMENT);
236236

237237
size_t i = 0;
238238
ReturnErrorOnFailure(mDelegate->CreateEntry(&i, entry, &fabric));
@@ -250,7 +250,7 @@ CHIP_ERROR AccessControl::UpdateEntry(const SubjectDescriptor * subjectDescripto
250250
const Entry & entry)
251251
{
252252
VerifyOrReturnError(IsInitialized(), CHIP_ERROR_INCORRECT_STATE);
253-
ReturnErrorCodeIf(!IsValid(entry), CHIP_ERROR_INVALID_ARGUMENT);
253+
VerifyOrReturnError(IsValid(entry), CHIP_ERROR_INVALID_ARGUMENT);
254254
ReturnErrorOnFailure(mDelegate->UpdateEntry(index, entry, &fabric));
255255
NotifyEntryChanged(subjectDescriptor, fabric, index, &entry, EntryListener::ChangeType::kUpdated);
256256
return CHIP_NO_ERROR;

src/access/AccessControl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ class AccessControl
501501
*/
502502
CHIP_ERROR CreateEntry(size_t * index, const Entry & entry, FabricIndex * fabricIndex = nullptr)
503503
{
504-
ReturnErrorCodeIf(!IsValid(entry), CHIP_ERROR_INVALID_ARGUMENT);
504+
VerifyOrReturnError(IsValid(entry), CHIP_ERROR_INVALID_ARGUMENT);
505505
VerifyOrReturnError(IsInitialized(), CHIP_ERROR_INCORRECT_STATE);
506506
return mDelegate->CreateEntry(index, entry, fabricIndex);
507507
}
@@ -551,7 +551,7 @@ class AccessControl
551551
*/
552552
CHIP_ERROR UpdateEntry(size_t index, const Entry & entry, const FabricIndex * fabricIndex = nullptr)
553553
{
554-
ReturnErrorCodeIf(!IsValid(entry), CHIP_ERROR_INVALID_ARGUMENT);
554+
VerifyOrReturnError(IsValid(entry), CHIP_ERROR_INVALID_ARGUMENT);
555555
VerifyOrReturnError(IsInitialized(), CHIP_ERROR_INCORRECT_STATE);
556556
return mDelegate->UpdateEntry(index, entry, fabricIndex);
557557
}

src/access/examples/ExampleAccessControlDelegate.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ CHIP_ERROR CopyViaInterface(const Entry & entry, EntryStorage & storage)
909909

910910
size_t subjectCount = 0;
911911
ReturnErrorOnFailure(entry.GetSubjectCount(subjectCount));
912-
ReturnErrorCodeIf(subjectCount > EntryStorage::kMaxSubjects, CHIP_ERROR_BUFFER_TOO_SMALL);
912+
VerifyOrReturnError(subjectCount <= EntryStorage::kMaxSubjects, CHIP_ERROR_BUFFER_TOO_SMALL);
913913
for (size_t i = 0; i < subjectCount; ++i)
914914
{
915915
NodeId subject = kUndefinedNodeId;
@@ -919,7 +919,7 @@ CHIP_ERROR CopyViaInterface(const Entry & entry, EntryStorage & storage)
919919

920920
size_t targetCount = 0;
921921
ReturnErrorOnFailure(entry.GetTargetCount(targetCount));
922-
ReturnErrorCodeIf(targetCount > EntryStorage::kMaxTargets, CHIP_ERROR_BUFFER_TOO_SMALL);
922+
VerifyOrReturnError(targetCount <= EntryStorage::kMaxTargets, CHIP_ERROR_BUFFER_TOO_SMALL);
923923
for (size_t i = 0; i < targetCount; ++i)
924924
{
925925
Target target;

src/access/tests/TestAccessControl.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -662,30 +662,30 @@ CHIP_ERROR CompareEntry(const Entry & entry, const EntryData & entryData)
662662
{
663663
AuthMode authMode = AuthMode::kNone;
664664
ReturnErrorOnFailure(entry.GetAuthMode(authMode));
665-
ReturnErrorCodeIf(authMode != entryData.authMode, CHIP_ERROR_INCORRECT_STATE);
665+
VerifyOrReturnError(authMode == entryData.authMode, CHIP_ERROR_INCORRECT_STATE);
666666
FabricIndex fabricIndex = kUndefinedFabricIndex;
667667
ReturnErrorOnFailure(entry.GetFabricIndex(fabricIndex));
668-
ReturnErrorCodeIf(fabricIndex != entryData.fabricIndex, CHIP_ERROR_INCORRECT_STATE);
668+
VerifyOrReturnError(fabricIndex == entryData.fabricIndex, CHIP_ERROR_INCORRECT_STATE);
669669
Privilege privilege = Privilege::kView;
670670
ReturnErrorOnFailure(entry.GetPrivilege(privilege));
671-
ReturnErrorCodeIf(privilege != entryData.privilege, CHIP_ERROR_INCORRECT_STATE);
671+
VerifyOrReturnError(privilege == entryData.privilege, CHIP_ERROR_INCORRECT_STATE);
672672
size_t subjectCount = 0;
673673
ReturnErrorOnFailure(entry.GetSubjectCount(subjectCount));
674-
ReturnErrorCodeIf(subjectCount != entryData.GetSubjectCount(), CHIP_ERROR_INCORRECT_STATE);
674+
VerifyOrReturnError(subjectCount == entryData.GetSubjectCount(), CHIP_ERROR_INCORRECT_STATE);
675675
for (size_t i = 0; i < subjectCount; ++i)
676676
{
677677
NodeId subject = kUndefinedNodeId;
678678
ReturnErrorOnFailure(entry.GetSubject(i, subject));
679-
ReturnErrorCodeIf(subject != entryData.subjects[i], CHIP_ERROR_INCORRECT_STATE);
679+
VerifyOrReturnError(subject == entryData.subjects[i], CHIP_ERROR_INCORRECT_STATE);
680680
}
681681
size_t targetCount = 0;
682682
ReturnErrorOnFailure(entry.GetTargetCount(targetCount));
683-
ReturnErrorCodeIf(targetCount != entryData.GetTargetCount(), CHIP_ERROR_INCORRECT_STATE);
683+
VerifyOrReturnError(targetCount == entryData.GetTargetCount(), CHIP_ERROR_INCORRECT_STATE);
684684
for (size_t i = 0; i < targetCount; ++i)
685685
{
686686
Target target;
687687
ReturnErrorOnFailure(entry.GetTarget(i, target));
688-
ReturnErrorCodeIf(target != entryData.targets[i], CHIP_ERROR_INCORRECT_STATE);
688+
VerifyOrReturnError(target == entryData.targets[i], CHIP_ERROR_INCORRECT_STATE);
689689
}
690690
return CHIP_NO_ERROR;
691691
}
@@ -724,7 +724,7 @@ CHIP_ERROR CompareAccessControl(AccessControl & ac, const EntryData * entryData,
724724
ReturnErrorOnFailure(ac.ReadEntry(i, entry));
725725
ReturnErrorOnFailure(CompareEntry(entry, *entryData));
726726
}
727-
ReturnErrorCodeIf(ac.ReadEntry(count, entry) == CHIP_NO_ERROR, CHIP_ERROR_INCORRECT_STATE);
727+
VerifyOrReturnError(ac.ReadEntry(count, entry) != CHIP_NO_ERROR, CHIP_ERROR_INCORRECT_STATE);
728728
return CHIP_NO_ERROR;
729729
}
730730

0 commit comments

Comments
 (0)