[Lldb-commits] [lldb] 983ed1b - [lldb] Set return object failed status even if error string is empty

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Thu Jun 17 04:20:58 PDT 2021


Author: David Spickett
Date: 2021-06-17T12:20:52+01:00
New Revision: 983ed1b58ef9d0f97c9cec2876f631e47609d437

URL: https://github.com/llvm/llvm-project/commit/983ed1b58ef9d0f97c9cec2876f631e47609d437
DIFF: https://github.com/llvm/llvm-project/commit/983ed1b58ef9d0f97c9cec2876f631e47609d437.diff

LOG: [lldb] Set return object failed status even if error string is empty

The idea is now that AppendError<...> will set eReturnStatusFailed
for you so you don't have to call SetStatus again.

Previously if the error message was empty, the status wouldn't
be set.

I don't think there are any sitautions where the message is in
fact empty but it potentially could be depending on where
we get the string from.

So let's set the status up front then return early if the message is empty.

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D104380

Added: 
    

Modified: 
    lldb/source/Interpreter/CommandReturnObject.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Interpreter/CommandReturnObject.cpp b/lldb/source/Interpreter/CommandReturnObject.cpp
index 531c1f246bd86..5edd9a3af9968 100644
--- a/lldb/source/Interpreter/CommandReturnObject.cpp
+++ b/lldb/source/Interpreter/CommandReturnObject.cpp
@@ -98,9 +98,9 @@ void CommandReturnObject::AppendWarning(llvm::StringRef in_string) {
 }
 
 void CommandReturnObject::AppendError(llvm::StringRef in_string) {
+  SetStatus(eReturnStatusFailed);
   if (in_string.empty())
     return;
-  SetStatus(eReturnStatusFailed);
   error(GetErrorStream()) << in_string.rtrim() << '\n';
 }
 
@@ -113,6 +113,7 @@ void CommandReturnObject::SetError(const Status &error,
 }
 
 void CommandReturnObject::SetError(llvm::StringRef error_str) {
+  SetStatus(eReturnStatusFailed);
   if (error_str.empty())
     return;
 
@@ -123,10 +124,10 @@ void CommandReturnObject::SetError(llvm::StringRef error_str) {
 // append "\n" to the end of it.
 
 void CommandReturnObject::AppendRawError(llvm::StringRef in_string) {
+  SetStatus(eReturnStatusFailed);
   if (in_string.empty())
     return;
   GetErrorStream() << in_string;
-  SetStatus(eReturnStatusFailed);
 }
 
 void CommandReturnObject::SetStatus(ReturnStatus status) { m_status = status; }


        


More information about the lldb-commits mailing list