Skip to content

Commit

Permalink
Fix reporting of event path errors in MTRBaseDevice. (#26822)
Browse files Browse the repository at this point in the history
Two main fixes here:

* Don't lose the prceise error if we have one in OnEventData.
* Use the right path key in our report dictionary for event errors.

The path key problem has not been shipped in any releases before, so no
backports needed.

The other changes are just aligning the attribute and event cases on checking
"is this a path we expected a report for?" before actually looking at the report
we got.
  • Loading branch information
bzbarsky-apple authored May 25, 2023
1 parent 6dcd58e commit ee1fdb3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/darwin/Framework/CHIP/MTRBaseDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -819,12 +819,14 @@ void OnAttributeData(
//
VerifyOrDie(!aPath.IsListItemOperation());

VerifyOrExit(aStatus.IsSuccess(), err = aStatus.ToChipError());
VerifyOrExit(
std::find_if(mAttributePathParamsList, mAttributePathParamsList + mAttributePathParamsSize,
[aPath](app::AttributePathParams & pathParam) -> bool { return pathParam.IsAttributePathSupersetOf(aPath); })
!= mAttributePathParamsList + mAttributePathParamsSize,
err = CHIP_ERROR_SCHEMA_MISMATCH);

VerifyOrExit(aStatus.IsSuccess(), err = aStatus.ToChipError());

VerifyOrExit(apData != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT);

SuccessOrExit(err = app::DataModel::Decode(*apData, value));
Expand Down Expand Up @@ -852,6 +854,9 @@ void OnEventData(const EventHeader & aEventHeader, TLV::TLVReader * apData, cons
})
!= mEventPathParamsList + mEventPathParamsSize,
err = CHIP_ERROR_SCHEMA_MISMATCH);

VerifyOrExit(apStatus == nullptr, err = apStatus->ToChipError());

VerifyOrExit(apData != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT);

SuccessOrExit(err = app::DataModel::Decode(*apData, value));
Expand Down Expand Up @@ -1366,7 +1371,7 @@ - (void)subscribeToAttributePaths:(NSArray<MTRAttributeRequestPath *> * _Nullabl
ConcreteEventPath pathCopy(*eventPath);
dispatch_async(queue, ^{
reportHandler(@[ @ {
MTRAttributePathKey : [[MTREventPath alloc] initWithPath:pathCopy],
MTREventPathKey : [[MTREventPath alloc] initWithPath:pathCopy],
MTRErrorKey : [MTRError errorForCHIPErrorCode:error]
} ],
nil);
Expand Down

0 comments on commit ee1fdb3

Please sign in to comment.