-
Notifications
You must be signed in to change notification settings - Fork 61
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
Improve error messages in pgagroal-cli
#403
Comments
Same issue happens in
while it should report something like command user requires a subcommand. |
Hello, @fluca1978. As we have discussed, I am ready to start working on this issue. In the near future, I will outline my proposed approach for us to discuss further, so we're aligned on the solution's direction before I dive deeper into implementation. |
While investigating this issue, I encountered a segmentation fault when running pgagroal-cli when no command is specified a command, but a password is specified. It appears the segfault occurs because the program attempts to free a password that points to a position in *argv. Steps to reproduce ./pgagroal-cli -h localhost -p 2345 -U test -P test Proposed Solution: Here is the relevant segment of the proposed fix (please notice my comments): // NOTE(decarv): adjust below
bool do_free = false;
// ...
/* Password */
if (password == NULL)
{
// NOTE(decarv): This inner check seems unnecessary since `password` is confirmed to be NULL above. Am I missing something?
if (password != NULL)
{
free(password);
password = NULL;
}
printf("Password : ");
password = pgagroal_get_password();
printf("\n");
// NOTE(decarv): add below
do_free = true;
}
// NOTE(decarv): Suggested to remove the following else block to avoid resetting `do_free` unnecessarily.
else
{
do_free = false;
} Ref.: Line 534 in 3b56518
Should I open a new issue to address this or would it be more appropriate to include the fix in this issue and corresponding PR? Edit: Add line ref. |
New issue |
Yeah, open a new issue. Line 538 in 3b56518
I would investigate/support from next monday. |
Based on previous discussion, I have considered two approaches for improving the error messages in 1. Modify
|
This is, according to me, the optimal solution, even if the longest and probably most difficult to implement, so I'm not sure it is worth for such a bunch of commands as
I don't like very much the idea of having a global variable. I was thinking about Another idea could be to define different functions, like
and |
Great! I think I have enough to draft a solution for now. I will come back to you should I have further questions. |
This commit attempts to improve the error messages for pgagroal-cli commands by modifying the parsing step. The command parsing now involves tables that guides the parsing of commands.
This commit attempts to improve the error messages for pgagroal-cli commands by modifying the parsing step. The command parsing now involves tables that guides the parsing of commands.
This commit attempts to improve the error messages for pgagroal-cli commands by modifying the parsing step. The command parsing now involves tables that guides the parsing of commands.
@decarv decarv@e0cb97b looks really promising, give me a few days to fully review your contribution. |
@fluca1978 Thank you! I actually changed my code last night and I feel I reached a point where I'm happy with it. I will open a PR so you can review it. |
This commit improves the error messages for pgagroal-cli and pgagroal-admin commands by modifying the parse_command function. The parsing step now involves two tables (command_table) defined in each cli.c and admin.c files, which guide the parsing of commands. Now adding a command with the structure "<command> [subcommand] [arg] [arg] ..." requires the addition of the command enum and its struct in the command_table.
This commit improves the error messages for pgagroal-cli and pgagroal-admin commands by modifying the parse_command function. The parsing step now involves two tables (command_table) defined in each cli.c and admin.c files, which guide the parsing of commands. Now adding a command with the structure "<command> [subcommand] [arg] [arg] ..." requires the addition of the command enum and its struct in the command_table.
This commit improves the error messages for pgagroal-cli and pgagroal-admin commands by modifying the parse_command function. The parsing step now involves two tables (command_table) defined in each cli.c and admin.c files, which guide the parsing of commands. Now adding a command with the structure "<command> [subcommand] [arg] [arg] ..." requires the addition of the command enum and its struct in the command_table.
This commit improves the error messages for pgagroal-cli and pgagroal-admin commands by modifying the parse_command function. The parsing step now involves two tables (command_table) defined in each cli.c and admin.c files, which guide the parsing of commands. Now adding a command with the structure "<command> [subcommand] [arg] [arg] ..." requires the addition of the command enum and its struct in the command_table.
This commit improves the error messages for pgagroal-cli and pgagroal-admin commands by modifying the parse_command function. The parsing step now involves two tables (command_table) defined in each cli.c and admin.c files, which guide the parsing of commands. Now adding a command with the structure "<command> [subcommand] [arg] [arg] ..." requires the addition of the command enum and its struct in the command_table.
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`.
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`.
Close via 11a1f47 |
While working on #399 I discovered that
pgagroal-cli
does not provide good error messages.For example.
pgagroal-cli conf
->pgagroal-cli: unknown command conf
while it should be something like command conf requires a subcommandpgagroal-cli conf get
->pgagroal-cli: unknown command conf
while it should be something like command conf get requires an argument nameSimilar behaviour for other commands.
The problem is that the handling of command line arguments in
pgagroal-cli
is done with a catch-all error block https://github.com/agroal/pgagroal/blob/master/src/cli.c#L652 so every rule that cannot fully parse jumps into such block and provides no useful information than a generic error.My idea is to trap errors near every parsing rule, so that the error message can have context-aware information to send back to the user.
The text was updated successfully, but these errors were encountered: