Skip to content

Commit 1c1e128

Browse files
committed
Report a useful error when someone passes an incorrect python class name.
(cherry picked from commit 9093f3c) (cherry picked from commit 408fc46)
1 parent 84ec9db commit 1c1e128

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

lldb/source/Commands/CommandObjectCommands.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,8 @@ class CommandObjectCommandsScriptAdd : public CommandObjectParsed,
15991599
auto cmd_obj_sp = interpreter->CreateScriptCommandObject(
16001600
m_options.m_class_name.c_str());
16011601
if (!cmd_obj_sp) {
1602-
result.AppendError("cannot create helper object");
1602+
result.AppendErrorWithFormatv("cannot create helper object for: "
1603+
"'{0}'", m_options.m_class_name);
16031604
return false;
16041605
}
16051606

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,8 +1976,11 @@ ScriptInterpreterPythonImpl::CreateScriptCommandObject(const char *class_name) {
19761976
PythonObject ret_val = LLDBSwigPythonCreateCommandObject(
19771977
class_name, m_dictionary_name.c_str(), debugger_sp);
19781978

1979-
return StructuredData::GenericSP(
1980-
new StructuredPythonObject(std::move(ret_val)));
1979+
if (ret_val.IsValid())
1980+
return StructuredData::GenericSP(
1981+
new StructuredPythonObject(std::move(ret_val)));
1982+
else
1983+
return {};
19811984
}
19821985

19831986
bool ScriptInterpreterPythonImpl::GenerateTypeScriptFunction(

lldb/test/API/commands/command/script/TestCommandScript.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ def cleanup():
164164
# This should not crash.
165165
self.runCmd('bug11569', check=False)
166166

167+
# Make sure that a reference to a non-existent class raises an error:
168+
bad_class_name = "LLDBNoSuchModule.LLDBNoSuchClass"
169+
self.expect("command script add wont-work --class {0}".format(bad_class_name), error=True, substrs = [bad_class_name])
170+
167171
def test_persistence(self):
168172
"""
169173
Ensure that function arguments meaningfully persist (and do not crash!)

0 commit comments

Comments
 (0)