-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[lldb] Remove CommandReturnObject::AppendRawError #171517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) ChangesRemove CommandReturnObject::AppendRawError and replace its two uses with AppendError, which correctly prefixes the message with "error:". The comment for the method is outdated and the prefixing is clearly desired in both situations. Full diff: https://github.com/llvm/llvm-project/pull/171517.diff 5 Files Affected:
diff --git a/lldb/include/lldb/Interpreter/CommandReturnObject.h b/lldb/include/lldb/Interpreter/CommandReturnObject.h
index 0742f1b836f5e..f6e60840256a4 100644
--- a/lldb/include/lldb/Interpreter/CommandReturnObject.h
+++ b/lldb/include/lldb/Interpreter/CommandReturnObject.h
@@ -129,8 +129,6 @@ class CommandReturnObject {
void AppendError(llvm::StringRef in_string);
- void AppendRawError(llvm::StringRef in_string);
-
void AppendErrorWithFormat(const char *format, ...)
__attribute__((format(printf, 2, 3)));
diff --git a/lldb/source/Commands/CommandObjectMultiword.cpp b/lldb/source/Commands/CommandObjectMultiword.cpp
index a369557cca845..e08b33cdce940 100644
--- a/lldb/source/Commands/CommandObjectMultiword.cpp
+++ b/lldb/source/Commands/CommandObjectMultiword.cpp
@@ -205,7 +205,7 @@ void CommandObjectMultiword::Execute(const char *args_string,
.str());
}
error_msg.append("\n");
- result.AppendRawError(error_msg.c_str());
+ result.AppendError(error_msg);
}
std::string CommandObjectMultiword::GetSubcommandsHintText() {
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index ffcc9ceeb2a93..cb6acfc9c29a9 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -3708,7 +3708,7 @@ CommandInterpreter::ResolveCommandImpl(std::string &command_line,
for (uint32_t i = 0; i < num_matches; ++i) {
error_msg.Printf("\t%s\n", matches.GetStringAtIndex(i));
}
- result.AppendRawError(error_msg.GetString());
+ result.AppendError(error_msg.GetString());
}
} else {
// We didn't have only one match, otherwise we wouldn't get here.
diff --git a/lldb/source/Interpreter/CommandReturnObject.cpp b/lldb/source/Interpreter/CommandReturnObject.cpp
index ef5bfae1bd1bd..85b058e97a679 100644
--- a/lldb/source/Interpreter/CommandReturnObject.cpp
+++ b/lldb/source/Interpreter/CommandReturnObject.cpp
@@ -173,15 +173,6 @@ StructuredData::ObjectSP CommandReturnObject::GetErrorData() {
return Serialize(m_diagnostics);
}
-// Similar to AppendError, but do not prepend 'Status: ' to message, and don't
-// append "\n" to the end of it.
-
-void CommandReturnObject::AppendRawError(llvm::StringRef in_string) {
- SetStatus(eReturnStatusFailed);
- assert(!in_string.empty() && "Expected a non-empty error message");
- GetErrorStream() << in_string;
-}
-
void CommandReturnObject::SetStatus(ReturnStatus status) { m_status = status; }
ReturnStatus CommandReturnObject::GetStatus() const { return m_status; }
diff --git a/lldb/test/Shell/Commands/command-wrong-subcommand-error-msg.test b/lldb/test/Shell/Commands/command-wrong-subcommand-error-msg.test
index 5365f81c19587..968a4d6fb9682 100644
--- a/lldb/test/Shell/Commands/command-wrong-subcommand-error-msg.test
+++ b/lldb/test/Shell/Commands/command-wrong-subcommand-error-msg.test
@@ -4,5 +4,5 @@
# RUN: not %lldb -b -o 'breakpoint foo' %t.out -o exit 2>&1 | FileCheck %s --check-prefix BP-MSG
# RUN: not %lldb -b -o 'watchpoint set foo' %t.out -o exit 2>&1 | FileCheck %s --check-prefix WP-MSG
# CHECK: at main.c:2:21
-# BP-MSG: "foo" is not a valid subcommand of "breakpoint". Valid subcommands are: add, clear, command, delete, disable, and others. Use "help breakpoint" to find out more.
-# WP-MSG: "foo" is not a valid subcommand of "watchpoint set". Valid subcommands are: expression, variable. Use "help watchpoint set" to find out more.
\ No newline at end of file
+# BP-MSG: error: "foo" is not a valid subcommand of "breakpoint". Valid subcommands are: add, clear, command, delete, disable, and others. Use "help breakpoint" to find out more.
+# WP-MSG: error: "foo" is not a valid subcommand of "watchpoint set". Valid subcommands are: expression, variable. Use "help watchpoint set" to find out more.
|
|
I observed the unexpected behavior when writing up #171514 |
🐧 Linux x64 Test Results
Failed Tests(click on a test name to see its output) lldb-apilldb-api.functionalities/abbreviation/TestAbbreviations.pylldb-api.functionalities/ambigous_commands/TestAmbiguousCommands.pyIf these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the |
b64da22 to
7673f13
Compare
Remove CommandReturnObject::AppendRawError and replace its two uses with AppendError, which correctly prefixes the message with "error:". The comment for the method is outdated and the prefixing is clearly desired in both situations.
7673f13 to
59a37b3
Compare
| for (uint32_t i = 0; i < num_matches; ++i) { | ||
| error_msg.Printf("\t%s\n", matches.GetStringAtIndex(i)); | ||
| } | ||
| result.AppendRawError(error_msg.GetString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you also want to uncapitalize Ambiguous on line 3705 above as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also remove the pointless \n at the end.
| self.assertEqual( | ||
| result.GetError(), | ||
| "Ambiguous command 'co'. Possible matches:\n\tcommand\n\tcontinue\n\tcorefile\n", | ||
| "error: Ambiguous command 'co'. Possible matches:\n\tcommand\n\tcontinue\n\tcorefile\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be "error: ambiguous..." right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, already put up #171519. I'll do the same for the newline.
| " Use \"help " + GetCommandName() + "\" to find out more.") | ||
| .str()); | ||
| } | ||
| error_msg.append("\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AppendError ends up trimming this "\n" from the end of the string, then putting another on on. So there's no reason to keep the append("\n") here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
CommandReturnObject::AppendRawErrorand replace its two uses withAppendError, which correctly prefixes the message witherror:. The comment for the method is outdated and the prefixing is clearly desired in both situations.