diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index f8b1e9431..aa0a7f757 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -4866,17 +4866,20 @@ void Interpreter::ProcessLine(char *aBuf) Arg args[kMaxArgs]; uint8_t argsLength; const Command *command; - otError error; + otError error = OT_ERROR_NONE; - VerifyOrExit(aBuf != nullptr && StringLength(aBuf, kMaxLineLength) <= kMaxLineLength - 1); + OT_ASSERT(aBuf != nullptr); - VerifyOrExit(Utils::CmdLineParser::ParseCmd(aBuf, argsLength, args, kMaxArgs) == OT_ERROR_NONE, - OutputLine("Error: too many args (max %d)", kMaxArgs)); + VerifyOrExit(StringLength(aBuf, kMaxLineLength) <= kMaxLineLength - 1, error = OT_ERROR_PARSE); + + SuccessOrExit(error = Utils::CmdLineParser::ParseCmd(aBuf, argsLength, args, kMaxArgs)); VerifyOrExit(argsLength >= 1); #if OPENTHREAD_CONFIG_DIAG_ENABLE - VerifyOrExit((!otDiagIsEnabled(mInstance) || (args[0] == "diag")), - OutputLine("under diagnostics mode, execute 'diag stop' before running any other commands.")); + VerifyOrExit((!otDiagIsEnabled(mInstance) || (args[0] == "diag")), { + OutputLine("under diagnostics mode, execute 'diag stop' before running any other commands."); + error = OT_ERROR_INVALID_STATE; + }); #endif command = Utils::LookupTable::Find(args[0].GetCString(), sCommands); @@ -4889,10 +4892,12 @@ void Interpreter::ProcessLine(char *aBuf) { error = ProcessUserCommands(argsLength, args); } - OutputResult(error); exit: - return; + if (error != OT_ERROR_NONE || argsLength > 0) + { + OutputResult(error); + } } otError Interpreter::ProcessUserCommands(uint8_t aArgsLength, Arg aArgs[]) diff --git a/tests/scripts/thread-cert/test_diag.py b/tests/scripts/thread-cert/test_diag.py index 9ddf3ef28..34b45ccdb 100755 --- a/tests/scripts/thread-cert/test_diag.py +++ b/tests/scripts/thread-cert/test_diag.py @@ -84,7 +84,7 @@ class TestDiag(thread_cert.TestCase): ('diag', 'diagnostics mode is disabled\r\n'), ( 'diag 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32', - r'Error: too many args \(max 32\)\r\n', + r'Error 7: InvalidArgs\r\n', ), ]