aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/vim.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2023-02-14 14:19:28 -0500
committerGitHub <noreply@github.com>2023-02-14 11:19:28 -0800
commit556f8646c01d1751cf39fe4df9c622899dceab9d (patch)
tree6262b53753d2f80a3305b76c7d1ec6e6b1f92b37 /src/nvim/api/vim.c
parente03ecb7d31c10aab8a8acbfb3cdd7ec558cd49eb (diff)
downloadrneovim-556f8646c01d1751cf39fe4df9c622899dceab9d.tar.gz
rneovim-556f8646c01d1751cf39fe4df9c622899dceab9d.tar.bz2
rneovim-556f8646c01d1751cf39fe4df9c622899dceab9d.zip
refactor(api): consistent VALIDATE messages #22262
Problem: Validation messages are not consistently formatted. - Parameter names sometimes are NOT quoted. - Descriptive names (non-parameters) sometimes ARE quoted. Solution: Always quote the `name` value passed to a VALIDATE macro _unless_ the value has whitespace.
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r--src/nvim/api/vim.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 50683ac403..3a93005841 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -654,12 +654,13 @@ Object nvim_get_var(String name, Error *err)
{
dictitem_T *di = tv_dict_find(&globvardict, name.data, (ptrdiff_t)name.size);
if (di == NULL) { // try to autoload script
- VALIDATE_S((script_autoload(name.data, name.size, false) && !aborting()), "key", name.data, {
+ bool found = script_autoload(name.data, name.size, false) && !aborting();
+ VALIDATE(found, "Key not found: %s", name.data, {
return (Object)OBJECT_INIT;
});
di = tv_dict_find(&globvardict, name.data, (ptrdiff_t)name.size);
}
- VALIDATE_S((di != NULL), "key (not found)", name.data, {
+ VALIDATE((di != NULL), "Key not found: %s", name.data, {
return (Object)OBJECT_INIT;
});
return vim_to_object(&di->di_tv);
@@ -986,7 +987,7 @@ Integer nvim_open_term(Buffer buffer, DictionaryOf(LuaRef) opts, Error *err)
v->data.luaref = LUA_NOREF;
break;
} else {
- VALIDATE_S(false, "key", k.data, {});
+ VALIDATE_S(false, "'opts' key", k.data, {});
}
}
@@ -1632,18 +1633,18 @@ Array nvim_call_atomic(uint64_t channel_id, Array calls, Arena *arena, Error *er
size_t i; // also used for freeing the variables
for (i = 0; i < calls.size; i++) {
- VALIDATE_T("calls item", kObjectTypeArray, calls.items[i].type, {
+ VALIDATE_T("'calls' item", kObjectTypeArray, calls.items[i].type, {
goto theend;
});
Array call = calls.items[i].data.array;
- VALIDATE((call.size == 2), "%s", "calls item must be a 2-item Array", {
+ VALIDATE_EXP((call.size == 2), "'calls' item", "2-item Array", NULL, {
goto theend;
});
VALIDATE_T("name", kObjectTypeString, call.items[0].type, {
goto theend;
});
String name = call.items[0].data.string;
- VALIDATE_T("args", kObjectTypeArray, call.items[1].type, {
+ VALIDATE_T("call args", kObjectTypeArray, call.items[1].type, {
goto theend;
});
Array args = call.items[1].data.array;
@@ -2108,10 +2109,10 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error *
VALIDATE_T("fillchar", kObjectTypeString, opts->fillchar.type, {
return result;
});
- VALIDATE((opts->fillchar.data.string.size != 0
- && ((size_t)utf_ptr2len(opts->fillchar.data.string.data)
- == opts->fillchar.data.string.size)),
- "%s", "Invalid fillchar: expected single character", {
+ VALIDATE_EXP((opts->fillchar.data.string.size != 0
+ && ((size_t)utf_ptr2len(opts->fillchar.data.string.data)
+ == opts->fillchar.data.string.size)),
+ "fillchar", "single character", NULL, {
return result;
});
fillchar = utf_ptr2char(opts->fillchar.data.string.data);