From 0ee1d8bc7554e47a87273f4f6c4a2e534de251de Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Thu, 21 Nov 2024 13:14:29 -0800 Subject: [PATCH] [lldb] Fix a regression in SBValue::GetObjectDescription() The old behavior was to return a null string in the error case,when refactoring the error handling I thought it would be a good idea to print the error in the description, but that breaks clients that try to print a description first and then do something else in the error case. The API is not great but it's clear that in-band errors are also not a good idea. rdar://133956263 --- lldb/source/API/SBValue.cpp | 6 ++++-- .../commands/expression/diagnostics/TestExprDiagnostics.py | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp index b35c82250d6ba..a707b9aa7589c 100644 --- a/lldb/source/API/SBValue.cpp +++ b/lldb/source/API/SBValue.cpp @@ -380,8 +380,10 @@ const char *SBValue::GetObjectDescription() { return nullptr; llvm::Expected str = value_sp->GetObjectDescription(); - if (!str) - return ConstString("error: " + toString(str.takeError())).AsCString(); + if (!str) { + llvm::consumeError(str.takeError()); + return nullptr; + } return ConstString(*str).AsCString(); } diff --git a/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py b/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py index b9b5bffb87e81..0806776aa6eb0 100644 --- a/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py +++ b/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py @@ -195,6 +195,10 @@ def test_error_type(self): value = frame.EvaluateExpression('#error("I am error.")') error = value.GetError() self.assertEqual(error.GetType(), lldb.eErrorTypeExpression) + value = frame.FindVariable("f") + self.assertTrue(value.IsValid()) + desc = value.GetObjectDescription() + self.assertEqual(desc, None) def test_command_expr_sbdata(self): """Test the structured diagnostics data"""