From 51590668f56ecd2781954024cdef6a686cadd1f4 Mon Sep 17 00:00:00 2001 From: Steven Hawkins Date: Thu, 29 Feb 2024 08:22:21 -0500 Subject: [PATCH] fix: provide a better error message when option parsing fails (#27354) closes: #16260 Signed-off-by: Steve Hawkins --- .../client/admin/cli/aesh/AeshConsoleCallbackImpl.java | 5 +++-- .../java/org/keycloak/testsuite/cli/admin/KcAdmTest.java | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/aesh/AeshConsoleCallbackImpl.java b/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/aesh/AeshConsoleCallbackImpl.java index fedaaa0c24..d9ad42187b 100644 --- a/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/aesh/AeshConsoleCallbackImpl.java +++ b/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/aesh/AeshConsoleCallbackImpl.java @@ -70,8 +70,9 @@ class AeshConsoleCallbackImpl extends AeshConsoleCallback { } catch (Exception e) { console.stop(); - if (e instanceof OptionParserException) { - System.err.println("Unknown command: " + aeshLine.getWords().get(0)); + if (e instanceof OptionParserException && "Option: - must be followed by a valid operator".equals(e.getMessage())) { + System.err.println("Please double check your command options, one or more of them are not specified correctly. " + + "It is possible to have unintentional overlap with other options. e.g. using --clientid will get mistaken for --client, however --cclientid is needed."); } else { System.err.println(e.getMessage()); } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cli/admin/KcAdmTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cli/admin/KcAdmTest.java index 8f2e5b4013..f019150e75 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cli/admin/KcAdmTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cli/admin/KcAdmTest.java @@ -226,6 +226,15 @@ public class KcAdmTest extends AbstractAdmCliTest { Assert.assertEquals("try help", "Try '" + CMD + " help set-password' for more information", exe.stderrLines().get(1)); } + @Test + public void testBadOverlappingOption() { + KcAdmExec exe = KcAdmExec.execute("config credentials --server http://localhost:8080 --realm master --username admin --password admin"); + + assertExitCodeAndStreamSizes(exe, 1, 0, 1); + Assert.assertEquals("stderr first line", "Please double check your command options, one or more of them are not specified correctly. " + + "It is possible to have unintentional overlap with other options. e.g. using --clientid will get mistaken for --client, however --cclientid is needed.", exe.stderrLines().get(0)); + } + @Test public void testCredentialsServerAndRealmWithDefaultConfig() { /*