diff --git a/examples/chip-tool/commands/clusters/ClusterCommand.h b/examples/chip-tool/commands/clusters/ClusterCommand.h index 31e3f387dfcb73..550bf33118bf7f 100644 --- a/examples/chip-tool/commands/clusters/ClusterCommand.h +++ b/examples/chip-tool/commands/clusters/ClusterCommand.h @@ -65,7 +65,7 @@ class ClusterCommand : public ModelCommand, public chip::app::CommandSender::Cal if (CHIP_NO_ERROR != error) { ChipLogError(chipTool, "Response Failure: %s", chip::ErrorStr(error)); - SetCommandExitStatus(error); + mError = error; return; } @@ -75,7 +75,7 @@ class ClusterCommand : public ModelCommand, public chip::app::CommandSender::Cal if (CHIP_NO_ERROR != error) { ChipLogError(chipTool, "Response Failure: Can not decode Data"); - SetCommandExitStatus(error); + mError = error; return; } } @@ -84,13 +84,13 @@ class ClusterCommand : public ModelCommand, public chip::app::CommandSender::Cal virtual void OnError(const chip::app::CommandSender * client, CHIP_ERROR error) override { ChipLogProgress(chipTool, "Error: %s", chip::ErrorStr(error)); - SetCommandExitStatus(error); + mError = error; } virtual void OnDone(chip::app::CommandSender * client) override { mCommandSender.reset(); - SetCommandExitStatus(CHIP_NO_ERROR); + SetCommandExitStatus(mError); } template @@ -112,6 +112,7 @@ class ClusterCommand : public ModelCommand, public chip::app::CommandSender::Cal chip::CommandId mCommandId; chip::Optional mTimedInteractionTimeoutMs; + CHIP_ERROR mError = CHIP_NO_ERROR; CustomArgument mPayload; std::unique_ptr mCommandSender; }; diff --git a/examples/chip-tool/commands/clusters/ReportCommand.h b/examples/chip-tool/commands/clusters/ReportCommand.h index 66919d0b3a3dac..9d39180a98331f 100644 --- a/examples/chip-tool/commands/clusters/ReportCommand.h +++ b/examples/chip-tool/commands/clusters/ReportCommand.h @@ -41,14 +41,14 @@ class ReportCommand : public ModelCommand, public chip::app::ReadClient::Callbac if (CHIP_NO_ERROR != error) { ChipLogError(chipTool, "Response Failure: %s", chip::ErrorStr(error)); - SetCommandExitStatus(error); + mError = error; return; } if (data == nullptr) { ChipLogError(chipTool, "Response Failure: No Data"); - SetCommandExitStatus(CHIP_ERROR_INTERNAL); + mError = CHIP_ERROR_INTERNAL; return; } @@ -56,7 +56,7 @@ class ReportCommand : public ModelCommand, public chip::app::ReadClient::Callbac if (CHIP_NO_ERROR != error) { ChipLogError(chipTool, "Response Failure: Can not decode Data"); - SetCommandExitStatus(error); + mError = error; return; } } @@ -70,7 +70,7 @@ class ReportCommand : public ModelCommand, public chip::app::ReadClient::Callbac if (CHIP_NO_ERROR != error) { ChipLogError(chipTool, "Response Failure: %s", chip::ErrorStr(error)); - SetCommandExitStatus(error); + mError = error; return; } } @@ -78,7 +78,7 @@ class ReportCommand : public ModelCommand, public chip::app::ReadClient::Callbac if (data == nullptr) { ChipLogError(chipTool, "Response Failure: No Data"); - SetCommandExitStatus(CHIP_ERROR_INTERNAL); + mError = CHIP_ERROR_INTERNAL; return; } @@ -86,7 +86,7 @@ class ReportCommand : public ModelCommand, public chip::app::ReadClient::Callbac if (CHIP_NO_ERROR != error) { ChipLogError(chipTool, "Response Failure: Can not decode Data"); - SetCommandExitStatus(error); + mError = error; return; } } @@ -94,13 +94,13 @@ class ReportCommand : public ModelCommand, public chip::app::ReadClient::Callbac void OnError(CHIP_ERROR error) override { ChipLogProgress(chipTool, "Error: %s", chip::ErrorStr(error)); - SetCommandExitStatus(error); + mError = error; } void OnDone() override { mReadClient.reset(); - SetCommandExitStatus(CHIP_NO_ERROR); + SetCommandExitStatus(mError); } void OnSubscriptionEstablished(uint64_t subscriptionId) override { OnAttributeSubscription(); } @@ -177,6 +177,8 @@ class ReportCommand : public ModelCommand, public chip::app::ReadClient::Callbac // mFabricFiltered is really only used by the attribute commands, but we end // up needing it in our class's shared code. chip::Optional mFabricFiltered; + + CHIP_ERROR mError = CHIP_NO_ERROR; }; class ReadAttribute : public ReportCommand diff --git a/examples/chip-tool/commands/clusters/WriteAttributeCommand.h b/examples/chip-tool/commands/clusters/WriteAttributeCommand.h index 5b1fed4f287f35..5b2382ae808c8e 100644 --- a/examples/chip-tool/commands/clusters/WriteAttributeCommand.h +++ b/examples/chip-tool/commands/clusters/WriteAttributeCommand.h @@ -68,21 +68,20 @@ class WriteAttribute : public ModelCommand, public chip::app::WriteClient::Callb if (CHIP_NO_ERROR != error) { ChipLogError(chipTool, "Response Failure: %s", chip::ErrorStr(error)); - SetCommandExitStatus(error); - return; + mError = error; } } void OnError(const chip::app::WriteClient * client, CHIP_ERROR error) override { ChipLogProgress(chipTool, "Error: %s", chip::ErrorStr(error)); - SetCommandExitStatus(error); + mError = error; } void OnDone(chip::app::WriteClient * client) override { mWriteClient.reset(); - SetCommandExitStatus(CHIP_NO_ERROR); + SetCommandExitStatus(mError); } template @@ -109,6 +108,7 @@ class WriteAttribute : public ModelCommand, public chip::app::WriteClient::Callb private: chip::ClusterId mClusterId; chip::AttributeId mAttributeId; + CHIP_ERROR mError = CHIP_NO_ERROR; chip::Optional mTimedInteractionTimeoutMs; chip::Optional mDataVersion = chip::NullOptional; CustomArgument mAttributeValue; diff --git a/examples/chip-tool/commands/common/CHIPCommand.cpp b/examples/chip-tool/commands/common/CHIPCommand.cpp index 55c778f57aa632..2aa8858ee733f6 100644 --- a/examples/chip-tool/commands/common/CHIPCommand.cpp +++ b/examples/chip-tool/commands/common/CHIPCommand.cpp @@ -62,7 +62,7 @@ CHIP_ERROR CHIPCommand::Run() ReturnLogErrorOnFailure(InitializeCommissioner(kIdentityGamma, kIdentityGammaFabricId, trustStore)); chip::DeviceLayer::PlatformMgr().ScheduleWork(RunQueuedCommand, reinterpret_cast(this)); - ReturnLogErrorOnFailure(StartWaiting(GetWaitDuration())); + CHIP_ERROR err = StartWaiting(GetWaitDuration()); Shutdown(); @@ -77,7 +77,7 @@ CHIP_ERROR CHIPCommand::Run() ReturnLogErrorOnFailure(ShutdownCommissioner(kIdentityGamma)); StopTracing(); - return CHIP_NO_ERROR; + return err; } void CHIPCommand::StartTracing()