diff --git a/src/app/BufferedReadCallback.cpp b/src/app/BufferedReadCallback.cpp index 3752a3e65aef08..d780504e80a6b5 100644 --- a/src/app/BufferedReadCallback.cpp +++ b/src/app/BufferedReadCallback.cpp @@ -36,13 +36,8 @@ void BufferedReadCallback::OnReportBegin() void BufferedReadCallback::OnReportEnd() { - CHIP_ERROR err = DispatchBufferedData(mBufferedPath, StatusIB(), true); - if (err != CHIP_NO_ERROR) - { - mCallback.OnError(err); - return; - } - + mLastError = DispatchBufferedData(mBufferedPath, StatusIB(), true); + ReturnOnFailure(mLastError); mCallback.OnReportEnd(); } @@ -230,21 +225,19 @@ CHIP_ERROR BufferedReadCallback::DispatchBufferedData(const ConcreteAttributePat void BufferedReadCallback::OnAttributeData(const ConcreteDataAttributePath & aPath, TLV::TLVReader * apData, const StatusIB & aStatus) { - CHIP_ERROR err; - // // First, let's dispatch to our registered callback any buffered up list data from previous calls. // - err = DispatchBufferedData(aPath, aStatus); - SuccessOrExit(err); + mLastError = DispatchBufferedData(aPath, aStatus); + ReturnOnFailure(mLastError); // // We buffer up list data (only if the status was successful) // if (aPath.IsListOperation() && aStatus.mStatus == Protocols::InteractionModel::Status::Success) { - err = BufferData(aPath, apData); - SuccessOrExit(err); + mLastError = BufferData(aPath, apData); + ReturnOnFailure(mLastError); } else { @@ -255,12 +248,6 @@ void BufferedReadCallback::OnAttributeData(const ConcreteDataAttributePath & aPa // Update our latched buffered path. // mBufferedPath = aPath; - -exit: - if (err != CHIP_NO_ERROR) - { - mCallback.OnError(err); - } } } // namespace app diff --git a/src/app/BufferedReadCallback.h b/src/app/BufferedReadCallback.h index b24257884e1a77..57931469bda25a 100644 --- a/src/app/BufferedReadCallback.h +++ b/src/app/BufferedReadCallback.h @@ -44,7 +44,19 @@ class BufferedReadCallback : public ReadClient::Callback private: /* - * Generates the reconsistuted TLV array from the stored individual list elements + * Get the last internal fatal error in BufferedReadCallback + * @retval #CHIP_NO_ERROR If the method succeeded. + * @retval #CHIP_ERROR_INVALID_TLV_ELEMENT + * If bufferred list data is not TLV Array + * @retval #CHIP_ERROR_NO_MEMORY + * If an attempt to allocate an buffer failed due to lack of + * memory. + * @retval other Other CHIP or platform-specific errors. + */ + CHIP_ERROR GetLastError() const override { return mLastError; } + + /* + * Generates the reconstituted TLV array from the stored individual list elements */ CHIP_ERROR GenerateListTLV(TLV::ScopedBufferTLVReader & reader); @@ -74,6 +86,7 @@ class BufferedReadCallback : public ReadClient::Callback void OnError(CHIP_ERROR aError) override { mBufferedList.clear(); + mLastError = CHIP_NO_ERROR; return mCallback.OnError(aError); } @@ -131,6 +144,7 @@ class BufferedReadCallback : public ReadClient::Callback ConcreteDataAttributePath mBufferedPath; std::vector mBufferedList; Callback & mCallback; + CHIP_ERROR mLastError = CHIP_NO_ERROR; }; } // namespace app diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp index 2d609eb1afa05a..b2837e19ceb9d6 100644 --- a/src/app/ReadClient.cpp +++ b/src/app/ReadClient.cpp @@ -868,8 +868,7 @@ CHIP_ERROR ReadClient::ProcessAttributeReportIBs(TLV::TLVReader & aAttributeRepo { err = CHIP_NO_ERROR; } - - return err; + return mpCallback.GetLastError(); } CHIP_ERROR ReadClient::ProcessEventReportIBs(TLV::TLVReader & aEventReportIBsReader) diff --git a/src/app/ReadClient.h b/src/app/ReadClient.h index d8b8a971db8c28..a1a69f0e22ae3a 100644 --- a/src/app/ReadClient.h +++ b/src/app/ReadClient.h @@ -284,6 +284,11 @@ class ReadClient : public Messaging::ExchangeDelegate * things like min/max intervals based on the session parameters). */ virtual void OnCASESessionEstablished(const SessionHandle & aSession, ReadPrepareParams & aSubscriptionParams) {} + + /* + * Get the last internal fatal error in callback + */ + virtual CHIP_ERROR GetLastError() const { return CHIP_NO_ERROR; } }; enum class InteractionType : uint8_t