diff --git a/src/controller/WriteInteraction.h b/src/controller/WriteInteraction.h index 4926e98b28c471..19e383d738efe8 100644 --- a/src/controller/WriteInteraction.h +++ b/src/controller/WriteInteraction.h @@ -50,8 +50,8 @@ class WriteCallback final : public app::WriteClient::Callback using OnErrorCallbackType = std::function; using OnDoneCallbackType = std::function; - WriteCallback(OnSuccessCallbackType aOnSuccess, OnErrorCallbackType aOnError, OnDoneCallbackType aOnDone) : - mOnSuccess(aOnSuccess), mOnError(aOnError), mOnDone(aOnDone), mCallback(this) + WriteCallback(OnSuccessCallbackType aOnSuccess, OnErrorCallbackType aOnError, OnDoneCallbackType aOnDone, bool aIsGroupWrite) : + mOnSuccess(aOnSuccess), mOnError(aOnError), mOnDone(aOnDone), mIsGroupWrite(aIsGroupWrite), mCallback(this) {} app::WriteClient::Callback * GetChunkedCallback() { return &mCallback; } @@ -88,6 +88,16 @@ class WriteCallback final : public app::WriteClient::Callback void OnDone(app::WriteClient * apWriteClient) override { + if (!mIsGroupWrite && !mCalledCallback) + { + // This can happen if the server sends a response with an empty + // WriteResponses list. Since we are not sending wildcard write + // paths, that's not a valid response and we should treat it as an + // error. Use the error we would have gotten if we in fact expected + // a nonempty list. + OnError(apWriteClient, CHIP_END_OF_TLV); + } + if (mOnDone != nullptr) { mOnDone(apWriteClient); @@ -104,6 +114,7 @@ class WriteCallback final : public app::WriteClient::Callback OnDoneCallbackType mOnDone = nullptr; bool mCalledCallback = false; + bool mIsGroupWrite = false; app::ChunkedWriteCallback mCallback; }; @@ -121,7 +132,7 @@ CHIP_ERROR WriteAttribute(const SessionHandle & sessionHandle, chip::EndpointId WriteCallback::OnDoneCallbackType onDoneCb = nullptr, const Optional & aDataVersion = NullOptional) { - auto callback = Platform::MakeUnique(onSuccessCb, onErrorCb, onDoneCb); + auto callback = Platform::MakeUnique(onSuccessCb, onErrorCb, onDoneCb, sessionHandle->IsGroupSession()); VerifyOrReturnError(callback != nullptr, CHIP_ERROR_NO_MEMORY); auto client = Platform::MakeUnique(app::InteractionModelEngine::GetInstance()->GetExchangeManager(),