diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2024-12-16 04:00:20 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-16 04:00:20 -0800 |
commit | 167a2383b9966ac227a77b0221088246e14ce75a (patch) | |
tree | d509817042d19ba96a3305abdc62f1f7a67054ab /src/nvim/api/vim.c | |
parent | 9c6a3703bb15d56fecdd962512f69f0ccf6d398c (diff) | |
download | rneovim-167a2383b9966ac227a77b0221088246e14ce75a.tar.gz rneovim-167a2383b9966ac227a77b0221088246e14ce75a.tar.bz2 rneovim-167a2383b9966ac227a77b0221088246e14ce75a.zip |
fix(api): not using TRY_WRAP, generic error messages #31595
Problem:
- API functions using `try_start` directly instead of `TRY_WRAP`, do not
surface the underlying error message, and instead show generic things
like "Failed to set buffer".
- Error handling code is duplicated in the API impl, instead of
delegating to the vim buffer/window handling logic.
Solution:
- Use `TRY_WRAP`.
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r-- | src/nvim/api/vim.c | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 42fc21deac..1acfa0d34b 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -596,6 +596,7 @@ ArrayOf(String) nvim_get_runtime_file(String name, Boolean all, Arena *arena, Er int flags = DIP_DIRFILE | (all ? DIP_ALL : 0); TryState tstate; + // XXX: intentionally not using `TRY_WRAP`, to avoid `did_emsg=false` in `try_end`. try_enter(&tstate); do_in_runtimepath((name.size ? name.data : ""), flags, find_runtime_cb, &cookie); vim_ignored = try_leave(&tstate, err); @@ -888,23 +889,13 @@ void nvim_set_current_buf(Buffer buffer, Error *err) { buf_T *buf = find_buffer_by_handle(buffer, err); - if (!buf || curwin->w_buffer == buf) { - return; - } - - if (curwin->w_p_wfb) { - api_set_error(err, kErrorTypeException, "%s", e_winfixbuf_cannot_go_to_buffer); + if (!buf) { return; } - try_start(); - int result = do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buf->b_fnum, 0); - if (!try_end(err) && result == FAIL) { - api_set_error(err, - kErrorTypeException, - "Failed to switch to buffer %d", - buffer); - } + TRY_WRAP(err, { + do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buf->b_fnum, 0); + }); } /// Gets the current list of window handles. |