aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/window.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2024-12-16 08:34:16 -0800
committerGitHub <noreply@github.com>2024-12-16 08:34:16 -0800
commit022449b5223659d515b78bada7de2fac8718820a (patch)
tree2ce4dd7b21d2ba4089308b877608f4dbc4166d99 /src/nvim/api/window.c
parentfb8372adb3b9f50d4d18eba6f650c3728353ab00 (diff)
downloadrneovim-022449b5223659d515b78bada7de2fac8718820a.tar.gz
rneovim-022449b5223659d515b78bada7de2fac8718820a.tar.bz2
rneovim-022449b5223659d515b78bada7de2fac8718820a.zip
fix(api): generic error messages, not using TRY_WRAP #31596
Problem: - API functions using `try_start` directly, do not surface the underlying error message, and instead show generic messages. - Error-handling code is duplicated in the API impl. - Failure modes are not tested. Solution: - Use `TRY_WRAP`. - Add tests.
Diffstat (limited to 'src/nvim/api/window.c')
-rw-r--r--src/nvim/api/window.c38
1 files changed, 14 insertions, 24 deletions
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c
index 170d5c6cdb..f5e8d8f086 100644
--- a/src/nvim/api/window.c
+++ b/src/nvim/api/window.c
@@ -182,14 +182,9 @@ void nvim_win_set_height(Window window, Integer height, Error *err)
return;
}
- if (height > INT_MAX || height < INT_MIN) {
- api_set_error(err, kErrorTypeValidation, "Height value outside range");
- return;
- }
-
- try_start();
- win_setheight_win((int)height, win);
- try_end(err);
+ TRY_WRAP(err, {
+ win_setheight_win((int)height, win);
+ });
}
/// Gets the window width
@@ -224,14 +219,9 @@ void nvim_win_set_width(Window window, Integer width, Error *err)
return;
}
- if (width > INT_MAX || width < INT_MIN) {
- api_set_error(err, kErrorTypeValidation, "Width value outside range");
- return;
- }
-
- try_start();
- win_setwidth_win((int)width, win);
- try_end(err);
+ TRY_WRAP(err, {
+ win_setwidth_win((int)width, win);
+ });
}
/// Gets a window-scoped (w:) variable
@@ -436,15 +426,15 @@ Object nvim_win_call(Window window, LuaRef fun, Error *err)
}
tabpage_T *tabpage = win_find_tabpage(win);
- try_start();
Object res = OBJECT_INIT;
- win_execute_T win_execute_args;
- if (win_execute_before(&win_execute_args, win, tabpage)) {
- Array args = ARRAY_DICT_INIT;
- res = nlua_call_ref(fun, NULL, args, kRetLuaref, NULL, err);
- }
- win_execute_after(&win_execute_args);
- try_end(err);
+ TRY_WRAP(err, {
+ win_execute_T win_execute_args;
+ if (win_execute_before(&win_execute_args, win, tabpage)) {
+ Array args = ARRAY_DICT_INIT;
+ res = nlua_call_ref(fun, NULL, args, kRetLuaref, NULL, err);
+ }
+ win_execute_after(&win_execute_args);
+ });
return res;
}