fix(api): make nvim_parse_cmd propagate errors

Makes `nvim_parse_cmd` propagate any errors that occur while parsing to
give the user a better idea of what's wrong with the command.
This commit is contained in:
Famiu Haque
2022-05-05 23:11:57 +06:00
parent 1eecea8449
commit 511f06a56e
3 changed files with 37 additions and 13 deletions

View File

@@ -802,10 +802,15 @@ Dictionary nvim_parse_cmd(String str, Dictionary opts, Error *err)
// Parse command line
exarg_T ea;
CmdParseInfo cmdinfo;
char_u *cmdline = (char_u *)string_to_cstr(str);
char *cmdline = string_to_cstr(str);
char *errormsg = NULL;
if (!parse_cmdline(cmdline, &ea, &cmdinfo)) {
api_set_error(err, kErrorTypeException, "Error while parsing command line");
if (!parse_cmdline(cmdline, &ea, &cmdinfo, &errormsg)) {
if (errormsg != NULL) {
api_set_error(err, kErrorTypeException, "Error while parsing command line: %s", errormsg);
} else {
api_set_error(err, kErrorTypeException, "Error while parsing command line");
}
goto end;
}