[Lldb-commits] [PATCH] D104525: [lldb] Assert that CommandResultObject error messages are not empty

David Spickett via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Jun 18 05:30:46 PDT 2021


DavidSpickett created this revision.
Herald added a subscriber: inglorion.
DavidSpickett requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

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')


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104525

Files:
  lldb/source/Interpreter/CommandReturnObject.cpp


Index: lldb/source/Interpreter/CommandReturnObject.cpp
===================================================================
--- lldb/source/Interpreter/CommandReturnObject.cpp
+++ lldb/source/Interpreter/CommandReturnObject.cpp
@@ -99,24 +99,18 @@
 
 void CommandReturnObject::AppendError(llvm::StringRef in_string) {
   SetStatus(eReturnStatusFailed);
-  if (in_string.empty())
-    return;
+  assert(in_string.size() && "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::AppendRawError(llvm::StringRef in_string) {
   SetStatus(eReturnStatusFailed);
-  if (in_string.empty())
-    return;
+  assert(in_string.size() && "Expected a non-empty error message");
   GetErrorStream() << in_string;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104525.352980.patch
Type: text/x-patch
Size: 1350 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210618/efb04b54/attachment.bin>


More information about the lldb-commits mailing list