Skip to content

Commit

Permalink
Don't clobber chip-tool error (#9504)
Browse files Browse the repository at this point in the history
* Don't clobber chip-tool error

#### Problem

82cf1b1 (PR #9086) could clobber a returned error code with a
different value `GetCommandExitStatus()`, which could lead to `chip-tool`
exiting successfully when it shouldn't. (This doesn't actually happen
at present because nothing sets `err` after `RunCommand()`, but could
be triggered by otherwise innocuous code changes.)

#### Change overview

Check for an existing error in preference to `GetCommandExitStatus()`.

#### Testing

Manual run of `chip-tool` with edits.

* stop task before getting status
  • Loading branch information
kpschoedel authored and pull[bot] committed Oct 13, 2021
1 parent e80ac5f commit 1306658
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions examples/chip-tool/commands/common/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,17 @@ int Commands::Run(int argc, char ** argv)
#endif // !CONFIG_USE_SEPARATE_EVENTLOOP

exit:
if (err != CHIP_NO_ERROR)
{
ChipLogError(chipTool, "Run command failure: %s", chip::ErrorStr(err));
}

#if CONFIG_USE_SEPARATE_EVENTLOOP
chip::DeviceLayer::PlatformMgr().StopEventLoopTask();
#endif // CONFIG_USE_SEPARATE_EVENTLOOP

if (command)
if ((err == CHIP_NO_ERROR) && (command != nullptr))
{
err = command->GetCommandExitStatus();
if (err != CHIP_NO_ERROR)
{
ChipLogError(chipTool, "Run command failure: %s", chip::ErrorStr(err));
}
}
if (err != CHIP_NO_ERROR)
{
ChipLogError(chipTool, "Run command failure: %s", chip::ErrorStr(err));
}

if (command)
Expand Down

0 comments on commit 1306658

Please sign in to comment.