From fd200bc988b528f89d4372897b03a967935a0a60 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 24 May 2023 22:04:10 -0400 Subject: [PATCH] Fix reporting of event path errors in MTRBaseDevice. 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. --- src/darwin/Framework/CHIP/MTRBaseDevice.mm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRBaseDevice.mm b/src/darwin/Framework/CHIP/MTRBaseDevice.mm index 151ec1beeb21de..6fb6b0aac72546 100644 --- a/src/darwin/Framework/CHIP/MTRBaseDevice.mm +++ b/src/darwin/Framework/CHIP/MTRBaseDevice.mm @@ -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)); @@ -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)); @@ -1366,7 +1371,7 @@ - (void)subscribeToAttributePaths:(NSArray * _Nullabl ConcreteEventPath pathCopy(*eventPath); dispatch_async(queue, ^{ reportHandler(@[ @ { - MTRAttributePathKey : [[MTREventPath alloc] initWithPath:pathCopy], + MTREventPathKey : [[MTREventPath alloc] initWithPath:pathCopy], MTRErrorKey : [MTRError errorForCHIPErrorCode:error] } ], nil);