diff options
| author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-09-18 22:37:59 -0300 | 
|---|---|---|
| committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-09-18 22:37:59 -0300 | 
| commit | 53d15c2c25199f8e44e9a8a74898f06a85e7c83b (patch) | |
| tree | c7d53772706ed78bee255100b328db11e3dc867e /src/nvim/api/vim.c | |
| parent | 67a16384a46c5eb51ba43d9150e95a1742cffbde (diff) | |
| parent | 4a8b52ea08bb5cf501cd20bce4744ae6c7edd9b1 (diff) | |
| download | rneovim-53d15c2c25199f8e44e9a8a74898f06a85e7c83b.tar.gz rneovim-53d15c2c25199f8e44e9a8a74898f06a85e7c83b.tar.bz2 rneovim-53d15c2c25199f8e44e9a8a74898f06a85e7c83b.zip | |
Merge PR #1199 'Improvements to API error handling'
Diffstat (limited to 'src/nvim/api/vim.c')
| -rw-r--r-- | src/nvim/api/vim.c | 49 | 
1 files changed, 23 insertions, 26 deletions
| diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 43f2aafdc8..93aa0439f0 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1,5 +1,6 @@  #include <assert.h>  #include <stdint.h> +#include <inttypes.h>  #include <stdbool.h>  #include <stdlib.h>  #include <string.h> @@ -117,7 +118,7 @@ Object vim_eval(String str, Error *err)    typval_T *expr_result = eval_expr((char_u *) str.data, NULL);    if (!expr_result) { -    set_api_error("Failed to eval expression", err); +    api_set_error(err, Exception, _("Failed to evaluate expression"));    }    if (!try_end(err)) { @@ -139,7 +140,7 @@ Object vim_eval(String str, Error *err)  Integer vim_strwidth(String str, Error *err)  {    if (str.size > INT_MAX) { -    set_api_error("String length is too high", err); +    api_set_error(err, Validation, _("String length is too high"));      return 0;    } @@ -194,7 +195,7 @@ ArrayOf(String) vim_list_runtime_paths(void)  void vim_change_directory(String dir, Error *err)  {    if (dir.size >= MAXPATHL) { -    set_api_error("directory string is too long", err); +    api_set_error(err, Validation, _("Directory string is too long"));      return;    } @@ -206,7 +207,7 @@ void vim_change_directory(String dir, Error *err)    if (vim_chdir((char_u *)string)) {      if (!try_end(err)) { -      set_api_error("failed to change directory", err); +      api_set_error(err, Exception, _("Failed to change directory"));      }      return;    } @@ -364,18 +365,13 @@ void vim_set_current_buffer(Buffer buffer, Error *err)    }    try_start(); -  if (do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buf->b_fnum, 0) == FAIL) { -    if (try_end(err)) { -      return; -    } - -    char msg[256]; -    snprintf(msg, sizeof(msg), "failed to switch to buffer %d", (int)buffer); -    set_api_error(msg, err); -    return; +  int result = do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buf->b_fnum, 0); +  if (!try_end(err) && result == FAIL) { +    api_set_error(err, +                  Exception, +                  _("Failed to switch to buffer %" PRIu64), +                  buffer);    } - -  try_end(err);  }  /// Gets the current list of window handles @@ -422,16 +418,12 @@ void vim_set_current_window(Window window, Error *err)    try_start();    goto_tabpage_win(win_find_tabpage(win), win); - -  if (win != curwin) { -    if (try_end(err)) { -      return; -    } -    set_api_error("did not switch to the specified window", err); -    return; +  if (!try_end(err) && win != curwin) { +    api_set_error(err, +                  Exception, +                  _("Failed to switch to window %" PRIu64), +                  window);    } - -  try_end(err);  }  /// Gets the current list of tabpage handles @@ -481,7 +473,12 @@ void vim_set_current_tabpage(Tabpage tabpage, Error *err)    try_start();    goto_tabpage_tp(tp, true, true); -  try_end(err); +  if (!try_end(err) && tp != curtab) { +    api_set_error(err, +                  Exception, +                  _("Failed to switch to tabpage %" PRIu64), +                  tabpage); +  }  }  /// Subscribes to event broadcasts @@ -524,7 +521,7 @@ void vim_register_provider(uint64_t channel_id, String feature, Error *err)    xstrlcpy(buf, feature.data, sizeof(buf));    if (!provider_register(buf, channel_id)) { -    set_api_error("Feature doesn't exist", err); +    api_set_error(err, Validation, _("Feature doesn't exist"));    }  } | 
