Author: David Spickett Date: 2021-06-21T09:44:47Z New Revision: 12ae3cb7ba5399b99c02e8a73c681192259e188f
URL: https://github.com/llvm/llvm-project/commit/12ae3cb7ba5399b99c02e8a73c681192259e188f DIFF: https://github.com/llvm/llvm-project/commit/12ae3cb7ba5399b99c02e8a73c681192259e188f.diff LOG: [lldb] Assert that CommandResultObject error messages are not empty The intention is now that AppendError/SetError/AppendRawError only be called with some message to show. This enforces that. For SetError with a Status and a fallback string first assert that the Status is a failure Status. Then it calls SetError(StringRef) which checks the message is valid. (which could be the fallback or the Status') Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D104525 Added: Modified: lldb/source/Interpreter/CommandReturnObject.cpp Removed: ################################################################################ diff --git a/lldb/source/Interpreter/CommandReturnObject.cpp b/lldb/source/Interpreter/CommandReturnObject.cpp index 5edd9a3af9968..d0d0ced2de482 100644 --- a/lldb/source/Interpreter/CommandReturnObject.cpp +++ b/lldb/source/Interpreter/CommandReturnObject.cpp @@ -99,24 +99,18 @@ void CommandReturnObject::AppendWarning(llvm::StringRef in_string) { void CommandReturnObject::AppendError(llvm::StringRef in_string) { SetStatus(eReturnStatusFailed); - if (in_string.empty()) - return; + assert(!in_string.empty() && "Expected a non-empty error message"); error(GetErrorStream()) << in_string.rtrim() << '\n'; } void CommandReturnObject::SetError(const Status &error, const char *fallback_error_cstr) { - const char *error_cstr = error.AsCString(); - if (error_cstr == nullptr) - error_cstr = fallback_error_cstr; - SetError(error_cstr); + assert(error.Fail() && "Expected a failed Status"); + SetError(error.AsCString(fallback_error_cstr)); } void CommandReturnObject::SetError(llvm::StringRef error_str) { SetStatus(eReturnStatusFailed); - if (error_str.empty()) - return; - AppendError(error_str); } @@ -125,8 +119,7 @@ void CommandReturnObject::SetError(llvm::StringRef error_str) { void CommandReturnObject::AppendRawError(llvm::StringRef in_string) { SetStatus(eReturnStatusFailed); - if (in_string.empty()) - return; + assert(!in_string.empty() && "Expected a non-empty error message"); GetErrorStream() << in_string; } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits