#1457: Improve CLI error messages with suggestions#1858
Conversation
- Add clearer messages when a command requires IDEasy project context. - Detect unknown options and suggest the closest valid option (Did you mean ...). - Suggest closest commandlet name for unknown commands. - Add tests for the new suggestion flows
Coverage Report for CI Build 26649937969Coverage increased (+0.09%) to 71.203%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions239 previously-covered lines in 5 files lost coverage.
Coverage Stats💛 - Coveralls |
…nvalid-args-or-commandlets
…nvalid-args-or-commandlets
-Added Error handling for Invalid Arguments -Added in ClI Error the installable Versions as a suggestion when an unfound version is entered
…-invalid-args-or-commandlets"
…-or-commandlets' of https://github.com/KarimALotfy/IDEasy into feature/1457-improve-CLI-error-messages-on-invalid-args-or-commandlets
MarvMa
left a comment
There was a problem hiding this comment.
Nice Work! This will help users in the future to understand incorrect inputs better and even get a recommendation. I tested the functionality on Windows using the following tests:
- delete settings file -> run
ide update-> the expected warning is beeing printed - run
ide udpate-> a suggestion is beeing printed
I left some comments regarding the naming of boolean methods and a comment on a nested if else clause. Except that everything looks fine to me 🚀
- Refactored methods in CliSuggester to match coding-conventions - Improved readability in run method in AbstractIdeContext by reducing nested code - Change in CHANGELOG.adoc
…r-messages-on-invalid-args-or-commandlets"
…nvalid-args-or-commandlets
MarvMa
left a comment
There was a problem hiding this comment.
Looks really clean, Nice Job 💯
…nvalid-args-or-commandlets
…nvalid-args-or-commandlets
hohwille
left a comment
There was a problem hiding this comment.
@KarimALotfy Wow. Thank you for your great PR. I looked at your test and immediately saw the beauty of your solution that brings great UX. Digging in your implementation I found that you used established IT algorithm (levenshtein distance) as a pattern to this problem. Awesome job 🥇
I really want to get this merged.
Sorry that I still have some review-comments and one is just a stupid question where I could not understand something. Typically, we can just resolve that thread but hopefully you can answer the question quickly to enlighten me. 😄
| if (cmd.isIdeHomeRequired() && (this.ideHome == null)) { | ||
| throw new CliException(getMessageNotInsideIdeProject(), ProcessResult.NO_IDE_HOME); | ||
| } else if (cmd.isIdeRootRequired() && (this.ideRoot == null)) { | ||
| throw new CliException(getMessageIdeRootNotFound(), ProcessResult.NO_IDE_ROOT); | ||
| } |
There was a problem hiding this comment.
shouldn't we log better feedback here?
We are throwing an exception here.
If I am not mistaken, this is not handled to invoke isMissingProjectContextHandled or am I missing something?
There was a problem hiding this comment.
Seems I am missing something. I was expecting that when we iterate over each commandlet and found one that is matching but has no project but requires one we would throw an exception here that is not catched in the while loop over all commandlets and therefore your new code after that loop is never executed.
However, my assumption since your test is green.
For today I want to complete the review and will not be able to debug and find it out but this confused me and maybe this should indicate we should rework something that is slightly odd.
|
|
||
| String name = commandlet.getName(); | ||
|
|
||
| step.error("The {} commandlet requires to be an IDEasy project to work.", name); |
There was a problem hiding this comment.
Message sounds confusing (a commandlet is never an IDEasy project).
You maybe should also add this to the log message:
| step.error("The {} commandlet requires to be an IDEasy project to work.", name); | |
| step.error("The {} commandlet requires an IDEasy project to work.", name); |
There was a problem hiding this comment.
Sorry, I just saw that I wrote this grammatically wrong message as suggestion in the story. So my bad and thanks for improving anyway 🙏
| /** | ||
| * Finds the {@link Commandlet} with the given name. | ||
| * | ||
| * @param name the name of the {@link Commandlet} to find. | ||
| * @return the {@link Commandlet} with the given name or {@code null} if no such {@link Commandlet} exists. | ||
| */ | ||
| private Commandlet findCommandletByName(String name) { | ||
| if (name == null) { | ||
| return null; | ||
| } | ||
| for (Commandlet c : this.commandletManager.getCommandlets()) { | ||
| if (name.equals(c.getName())) { | ||
| return c; | ||
| } | ||
| } | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Why not using this that gives us the same result in O(1) (from a map)?
…nvalid-args-or-commandlets
Improve CLI error messages with suggestions
This PR fixes #1457
Implemented changes:
(Reused from PR : "#1643 improve ux on syntax error #1856" of improve UX on CLI syntax error #1643 by @satorus )
Checklist for this PR
Make sure everything is checked before merging this PR. For further info please also see
our DoD.
mvn clean testlocally all tests pass and build is successful#«issue-id»: «brief summary»(e.g.#921: fixed setup.bat). If no issue ID exists, title only.In Progressand assigned to you or there is no issue (might happen for very small PRs)with
internal