-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#403][#410] Improve error messages for pgagroal-cli #411
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very good job and it almost reflect what I had in mind.
I think there is really a little more to do to mark this as complete.
Thank you for your feedback, @fluca1978. My main goal with this PR was to seek your insights regarding my implementation and identify areas for improvement based on your vision. Given your response suggests I'm on the right track, I'd like to discuss additional ideas (below) aimed at simplifying our new command handling approach. As for the issues you highlighted above, I will address them later this evening. 1. Refining Command Execution through Callbacks int (*action)(struct pgagroal_parsed_command* cmd) // returns exit_error The With this, eliminating the Initially, I hesitated to implement these changes as they would necessitate further modifications to the existing code. What do you think? 2. Simplifying Error Handling |
This is clearly an optimal solution, even if I think it is probably too much for the needs of the project.
It's not essential, it could be beneficial only if we are not sure at which branch the error is raised and we need to try another branch, otherwise it is fine to output it directly having clear that this also means exiting from the parsing loop, which may be too early (?). |
6bb59bb
to
d25097a
Compare
While attempting to implement the callback based structure, I found myself redesigning the entire file, which wasn't the goal, so I decided to abort that approach. Could you check the PR and let me know if it looks good to you? I'm here to help with any adjustments you need. |
4911d70
to
e57675d
Compare
e57675d
to
19f30dc
Compare
@decarv I think the last commit is fine. Thanks. @jesperpedersen PTAL commit 19f30dc |
Otherwise it looks good |
This commit improves the error messages for pgagroal-cli and pgagroal-admin commands by modifying the `parse_command` function. `parse_command` now involves the interpretation of a `command_table` of `struct pgagroal_command`, defined in each cli.c and admin.c files. The `struct pgagroal_command` holds, beyond other things, the command, the subcommand and the accepted count of arguments. With this information, `parse_command` is now able to display error messages when (a) the typed command is invalid, (b) the typed command requires a subcommand, (c) the typed subcommand is invalid, or when, (d) for the typed command, there are too few or too many arguments. Now adding a command with the same invoking structure as the others (i.e., "<command> [subcommand] [arg] [arg] ...") requires inserting an entry in the `command_table` by filling the `struct pgagroal_command`.
19f30dc
to
11a1f47
Compare
Merged. Thanks for your contribution ! |
Thank you @fluca1978 and @jesperpedersen for the help! |
This commit improves the error messages for pgagroal-cli and pgagroal-admin commands by modifying the parse_command function.
It also tries to simplify adding new commands. Now adding a command with the structure " [subcommand] [arg] [arg] ..." requires the addition of the command enum and its struct in the
command_table
.This means that the command parsing now involves the interpretation of a command_table defined in each cli.c and admin.c files.