diff --git a/examples/chip-tool/commands/common/Commands.cpp b/examples/chip-tool/commands/common/Commands.cpp index ea8d5e4d8b52f3..aa98ac9dc38871 100644 --- a/examples/chip-tool/commands/common/Commands.cpp +++ b/examples/chip-tool/commands/common/Commands.cpp @@ -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)