diff options
author | Diana Z <dzigterman@chromium.org> | 2022-03-31 09:57:26 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-03-31 20:38:19 +0000 |
commit | 14525b74cdfa27011d437c01b6ce2e783c3ba215 (patch) | |
tree | 0523aef7bec2739cb5f8ece5092e65e162612326 /zephyr | |
parent | 1d844062cdf82d56cd4190f92c2fab592da7bc36 (diff) | |
download | chrome-ec-14525b74cdfa27011d437c01b6ce2e783c3ba215.tar.gz |
Zephyr: Print more on command errors
When a command fails, notify the user of the failure and print out the
command help. If the failure was a generic parameter error, then also
print out a readable string for that specific issue.
BRANCH=None
BUG=b:226595697
TEST=on skyrim, run accelrate with no parameters and observe a helpful
error print
22-03-31 10:00:38.085 ec:~$ accelrate
22-03-31 10:00:40.751 Wrong number of parameters
22-03-31 10:00:40.752 Read or write accelerometer ODR
22-03-31 10:00:40.755 Usage: accelrate id [data [roundup]]
Signed-off-by: Diana Z <dzigterman@chromium.org>
Change-Id: Ia490657ef4d8ac2a77590eb5930763f5d23660bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3564078
Reviewed-by: Wai-Hong Tam <waihong@google.com>
Commit-Queue: Wai-Hong Tam <waihong@google.com>
Diffstat (limited to 'zephyr')
-rw-r--r-- | zephyr/shim/src/console.c | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/zephyr/shim/src/console.c b/zephyr/shim/src/console.c index fb587e8fbc..1aa29c9d3c 100644 --- a/zephyr/shim/src/console.c +++ b/zephyr/shim/src/console.c @@ -185,9 +185,22 @@ void uart_shell_set_priority(int prio) k_thread_priority_set(shell_zephyr->ctx->tid, shell_priority); } +#ifdef CONFIG_SHELL_HELP +static void print_console_help(char *name, + const struct zephyr_console_command *command) +{ + if (command->help) + printk("%s\n", command->help); + if (command->argdesc) + printk("Usage: %s %s\n", name, command->argdesc); +} +#endif + int zshim_run_ec_console_command(const struct zephyr_console_command *command, size_t argc, char **argv) { + int ret; + /* * The Zephyr shell only displays the help string and not * the argument descriptor when passing "-h" or "--help". Mimic the @@ -198,16 +211,28 @@ int zshim_run_ec_console_command(const struct zephyr_console_command *command, if (!command->help && !command->argdesc) break; if (!strcmp(argv[i], "help")) { - if (command->help) - printk("%s\n", command->help); - if (command->argdesc) - printk("Usage: %s\n", command->argdesc); + print_console_help(argv[0], command); return 0; } } #endif - return command->handler(argc, argv); + ret = command->handler(argc, argv); + if (ret == EC_SUCCESS) + return ret; + + /* Print common parameter error conditions and help on error */ + if (ret >= EC_ERROR_PARAM1 && ret < EC_ERROR_PARAM_COUNT) + printk("Parameter %d invalid\n", ret - EC_ERROR_PARAM1 + 1); + else if (ret == EC_ERROR_PARAM_COUNT) + printk("Wrong number of parameters\n"); + else + printk("Command returned error: %d\n", ret); + +#ifdef CONFIG_SHELL_HELP + print_console_help(argv[0], command); +#endif + return ret; } #if defined(CONFIG_CONSOLE_CHANNEL) && DT_NODE_EXISTS(DT_PATH(ec_console)) |