Skip to content

Commit cf0be7b

Browse files
[lldb] Add actionable feedback when overwriting a command fails (llvm#76030)
If adding a user commands fails because a command with the same name already exists, we only say that "force replace is not set" without telling the user _how_ to set it. There are two ways to do so; this commit changes the error message to mention both.
1 parent e6d2bb0 commit cf0be7b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,11 @@ Status CommandInterpreter::AddUserCommand(llvm::StringRef name,
11601160

11611161
if (UserCommandExists(name)) {
11621162
if (!can_replace) {
1163-
result.SetErrorString("user command exists and force replace not set");
1163+
result.SetErrorStringWithFormatv(
1164+
"user command \"{0}\" already exists and force replace was not set "
1165+
"by --overwrite or 'settings set interpreter.require-overwrite "
1166+
"false'",
1167+
name);
11641168
return result;
11651169
}
11661170
if (cmd_sp->IsMultiwordObject()) {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,19 @@ def cleanup():
161161
)
162162
self.expect("my_command", substrs=["a.out"])
163163

164+
# Test that without --overwrite we are not allowed to redefine the command.
165+
self.expect(
166+
"command script add my_command --class welcome.TargetnameCommand",
167+
substrs=[
168+
(
169+
'user command "my_command" already exists and force replace was'
170+
" not set by --overwrite or 'settings set"
171+
" interpreter.require-overwrite false'"
172+
),
173+
],
174+
error=True,
175+
)
176+
164177
self.runCmd("command script clear")
165178

166179
self.expect(

0 commit comments

Comments
 (0)