[lldb] Fix a regression in SBValue::GetObjectDescription() (#117242)

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
This commit is contained in:
Adrian Prantl
2024-11-21 15:38:49 -08:00
committed by GitHub
parent 6a8a4d51a4
commit 7553fb1274
2 changed files with 8 additions and 2 deletions

View File

@@ -380,8 +380,10 @@ const char *SBValue::GetObjectDescription() {
return nullptr;
llvm::Expected<std::string> 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();
}

View File

@@ -195,6 +195,10 @@ note: candidate function not viable: requires single argument 'x', but 2 argumen
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"""