Skip to content

Commit

Permalink
Reset error state when shutting down chip-tool commands. (#20818)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Oct 10, 2023
1 parent 16a1fdc commit 05f7bb8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions examples/chip-tool/commands/clusters/ClusterCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions examples/chip-tool/commands/clusters/ReportCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
6 changes: 6 additions & 0 deletions examples/chip-tool/commands/clusters/WriteAttributeCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@
return CHIP_NO_ERROR;
}

void ModelCommand::Shutdown() { ResetArguments(); }
void ModelCommand::Shutdown()
{
ResetArguments();
CHIPCommandBridge::Shutdown();
}

0 comments on commit 05f7bb8

Please sign in to comment.