From bd077fe03193899563ea86c63e9ec18b6da32485 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Sat, 16 Jul 2022 03:18:18 -0400 Subject: [PATCH] Reset error state when shutting down chip-tool commands. (#20818) Some commands store an error status. If they fail, the next invocation of the same command in interactive mode will also claim to have failed, even if it succeeded, because the error status carries over. The fix is to reset the error status on Shutdown of the command. --- examples/chip-tool/commands/clusters/ClusterCommand.h | 6 ++++++ examples/chip-tool/commands/clusters/ReportCommand.h | 1 + .../chip-tool/commands/clusters/WriteAttributeCommand.h | 6 ++++++ .../commands/clusters/ClusterCommandBridge.h | 6 ++++++ .../commands/clusters/ModelCommandBridge.mm | 6 +++++- 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/examples/chip-tool/commands/clusters/ClusterCommand.h b/examples/chip-tool/commands/clusters/ClusterCommand.h index 81386cddd195aa..70875643691edf 100644 --- a/examples/chip-tool/commands/clusters/ClusterCommand.h +++ b/examples/chip-tool/commands/clusters/ClusterCommand.h @@ -124,6 +124,12 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub } } + void Shutdown() override + { + mError = CHIP_NO_ERROR; + ModelCommand::Shutdown(); + } + protected: ClusterCommand(const char * commandName, CredentialIssuerCommands * credsIssuerConfig) : InteractionModelCommands(this), ModelCommand(commandName, credsIssuerConfig) diff --git a/examples/chip-tool/commands/clusters/ReportCommand.h b/examples/chip-tool/commands/clusters/ReportCommand.h index 98f8f6de772051..694507c410c7f8 100644 --- a/examples/chip-tool/commands/clusters/ReportCommand.h +++ b/examples/chip-tool/commands/clusters/ReportCommand.h @@ -98,6 +98,7 @@ class ReportCommand : public InteractionModelReports, public ModelCommand, publi { // We don't shut down InteractionModelReports here; we leave it for // Cleanup to handle. + mError = CHIP_NO_ERROR; ModelCommand::Shutdown(); } diff --git a/examples/chip-tool/commands/clusters/WriteAttributeCommand.h b/examples/chip-tool/commands/clusters/WriteAttributeCommand.h index 57cad5cbf7f0cc..1cb6ff35383628 100644 --- a/examples/chip-tool/commands/clusters/WriteAttributeCommand.h +++ b/examples/chip-tool/commands/clusters/WriteAttributeCommand.h @@ -149,6 +149,12 @@ class WriteAttribute : public InteractionModelWriter, public ModelCommand, publi dataVersion); } + void Shutdown() override + { + mError = CHIP_NO_ERROR; + ModelCommand::Shutdown(); + } + protected: WriteAttribute(const char * attributeName, CredentialIssuerCommands * credsIssuerConfig) : InteractionModelWriter(this), ModelCommand("write", credsIssuerConfig) diff --git a/examples/darwin-framework-tool/commands/clusters/ClusterCommandBridge.h b/examples/darwin-framework-tool/commands/clusters/ClusterCommandBridge.h index 8aa6456f1ef73b..8cc84613e537f3 100644 --- a/examples/darwin-framework-tool/commands/clusters/ClusterCommandBridge.h +++ b/examples/darwin-framework-tool/commands/clusters/ClusterCommandBridge.h @@ -101,6 +101,12 @@ class ClusterCommand : public ModelCommand { return CHIP_NO_ERROR; } + void Shutdown() override + { + mError = nil; + ModelCommand::Shutdown(); + } + protected: ClusterCommand(const char * _Nonnull commandName) : ModelCommand(commandName) diff --git a/examples/darwin-framework-tool/commands/clusters/ModelCommandBridge.mm b/examples/darwin-framework-tool/commands/clusters/ModelCommandBridge.mm index 31ab9d8cba1038..e8387b8dda5b84 100644 --- a/examples/darwin-framework-tool/commands/clusters/ModelCommandBridge.mm +++ b/examples/darwin-framework-tool/commands/clusters/ModelCommandBridge.mm @@ -53,4 +53,8 @@ return CHIP_NO_ERROR; } -void ModelCommand::Shutdown() { ResetArguments(); } +void ModelCommand::Shutdown() +{ + ResetArguments(); + CHIPCommandBridge::Shutdown(); +}