https://github.com/felipepiovezan updated https://github.com/llvm/llvm-project/pull/76030
>From a9a1cbc1ac42b2eb66dac8a60aa9d8f54df291c3 Mon Sep 17 00:00:00 2001 From: Felipe de Azevedo Piovezan <fpiove...@apple.com> Date: Mon, 18 Dec 2023 11:26:41 -0300 Subject: [PATCH 1/2] [lldb] Add actionable feedback when overwriting a command fails 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. --- lldb/source/Interpreter/CommandInterpreter.cpp | 4 +++- .../API/commands/command/script/TestCommandScript.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index e1275ce711fc17..3d5ecd0612a640 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -1160,7 +1160,9 @@ Status CommandInterpreter::AddUserCommand(llvm::StringRef name, if (UserCommandExists(name)) { if (!can_replace) { - result.SetErrorString("user command exists and force replace not set"); + result.SetErrorString( + "user command exists and force replace not set by --overwrite or " + "'settings set interpreter.require-overwrite false'"); return result; } if (cmd_sp->IsMultiwordObject()) { diff --git a/lldb/test/API/commands/command/script/TestCommandScript.py b/lldb/test/API/commands/command/script/TestCommandScript.py index cac11834fa7364..1e1d9b728a965d 100644 --- a/lldb/test/API/commands/command/script/TestCommandScript.py +++ b/lldb/test/API/commands/command/script/TestCommandScript.py @@ -161,6 +161,17 @@ def cleanup(): ) self.expect("my_command", substrs=["a.out"]) + # Test that without --overwrite we are not allowed to redefine the command. + self.expect( + "command script add my_command --class welcome.TargetnameCommand", + substrs=[ + "cannot add command: user command exists and force replace not set", + "--overwrite", + "settings set interpreter.require-overwrite false", + ], + error=True, + ) + self.runCmd("command script clear") self.expect( >From 8b278f99e84dc7cc6edb316a203091d4b79915fa Mon Sep 17 00:00:00 2001 From: Felipe de Azevedo Piovezan <fpiove...@apple.com> Date: Wed, 20 Dec 2023 08:02:15 -0300 Subject: [PATCH 2/2] fixup! [lldb] Add actionable feedback when overwriting a command fails --- lldb/source/Interpreter/CommandInterpreter.cpp | 8 +++++--- .../test/API/commands/command/script/TestCommandScript.py | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 3d5ecd0612a640..00651df48b6224 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -1160,9 +1160,11 @@ Status CommandInterpreter::AddUserCommand(llvm::StringRef name, if (UserCommandExists(name)) { if (!can_replace) { - result.SetErrorString( - "user command exists and force replace not set by --overwrite or " - "'settings set interpreter.require-overwrite false'"); + result.SetErrorStringWithFormatv( + "user command \"{0}\" already exists and force replace was not set " + "by --overwrite or 'settings set interpreter.require-overwrite " + "false'", + name); return result; } if (cmd_sp->IsMultiwordObject()) { diff --git a/lldb/test/API/commands/command/script/TestCommandScript.py b/lldb/test/API/commands/command/script/TestCommandScript.py index 1e1d9b728a965d..850552032902fd 100644 --- a/lldb/test/API/commands/command/script/TestCommandScript.py +++ b/lldb/test/API/commands/command/script/TestCommandScript.py @@ -165,9 +165,11 @@ def cleanup(): self.expect( "command script add my_command --class welcome.TargetnameCommand", substrs=[ - "cannot add command: user command exists and force replace not set", - "--overwrite", - "settings set interpreter.require-overwrite false", + ( + 'user command "my_command" already exists and force replace was' + " not set by --overwrite or 'settings set" + " interpreter.require-overwrite false'" + ), ], error=True, ) _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits