[Lldb-commits] [lldb] [lldb/Interpreter] Surface Python exceptions from scripted extensions (PR #198153)

via lldb-commits lldb-commits at lists.llvm.org
Mon Jul 27 16:54:02 PDT 2026


================
@@ -62,18 +62,20 @@ class ScriptedInterface {
   static Ret ErrorWithMessage(llvm::StringRef caller_name,
                               llvm::StringRef error_msg, Status &error,
                               LLDBLog log_category = LLDBLog::Process) {
+    // Log the error for debugging (includes function signature for context).
     LLDB_LOGF(GetLog(log_category), "%s ERROR = %s", caller_name.data(),
               error_msg.data());
-    std::string full_error_message =
-        llvm::Twine(caller_name + llvm::Twine(" ERROR = ") +
-                    llvm::Twine(error_msg))
-            .str();
-    if (const char *detailed_error = error.AsCString())
-      full_error_message +=
-          llvm::Twine(llvm::Twine(" (") + llvm::Twine(detailed_error) +
-                      llvm::Twine(")"))
-              .str();
-    error = Status(std::move(full_error_message));
+
+    // For user-facing messages, just pass through the Status if it already
+    // has detailed information (like Python tracebacks); otherwise set it.
+    llvm::StringRef existing_error = error.AsCString();
+    if (!error.Fail() || existing_error.empty()) {
+      // Status is empty, populate it with the simple error message.
+      error = Status::FromErrorString(error_msg.data());
+    }
+    // If Status already has content, leave it as-is (it has the Python
+    // traceback).
+
----------------
jimingham wrote:

Right, but the way this is written, if the incoming `error` is in a fail state, and already has text in it, this code won't add the string from `error_msg` to the error, it will just return it as is.
Didn't you want to prepend what's in `error_msg` TO the extant content in `error`?

https://github.com/llvm/llvm-project/pull/198153


More information about the lldb-commits mailing list