mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
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.
This commit is contained in:
@@ -669,16 +669,9 @@ void nvim_set_current_dir(String dir, Error *err)
|
||||
memcpy(string, dir.data, dir.size);
|
||||
string[dir.size] = NUL;
|
||||
|
||||
try_start();
|
||||
|
||||
if (!changedir_func(string, kCdScopeGlobal)) {
|
||||
if (!try_end(err)) {
|
||||
api_set_error(err, kErrorTypeException, "Failed to change directory");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try_end(err);
|
||||
TRY_WRAP(err, {
|
||||
changedir_func(string, kCdScopeGlobal);
|
||||
});
|
||||
}
|
||||
|
||||
/// Gets the current line.
|
||||
@@ -942,14 +935,9 @@ void nvim_set_current_win(Window window, Error *err)
|
||||
return;
|
||||
}
|
||||
|
||||
try_start();
|
||||
goto_tabpage_win(win_find_tabpage(win), win);
|
||||
if (!try_end(err) && win != curwin) {
|
||||
api_set_error(err,
|
||||
kErrorTypeException,
|
||||
"Failed to switch to window %d",
|
||||
window);
|
||||
}
|
||||
TRY_WRAP(err, {
|
||||
goto_tabpage_win(win_find_tabpage(win), win);
|
||||
});
|
||||
}
|
||||
|
||||
/// Creates a new, empty, unnamed buffer.
|
||||
@@ -1208,14 +1196,9 @@ void nvim_set_current_tabpage(Tabpage tabpage, Error *err)
|
||||
return;
|
||||
}
|
||||
|
||||
try_start();
|
||||
goto_tabpage_tp(tp, true, true);
|
||||
if (!try_end(err) && tp != curtab) {
|
||||
api_set_error(err,
|
||||
kErrorTypeException,
|
||||
"Failed to switch to tabpage %d",
|
||||
tabpage);
|
||||
}
|
||||
TRY_WRAP(err, {
|
||||
goto_tabpage_tp(tp, true, true);
|
||||
});
|
||||
}
|
||||
|
||||
/// Pastes at cursor (in any mode), and sets "redo" so dot (|.|) will repeat the input. UIs call
|
||||
|
Reference in New Issue
Block a user