Mercurial > vim
changeset 23891:650070143c56 v8.2.2488
patch 8.2.2488: json_encode() gives generic argument error
Commit: https://github.com/vim/vim/commit/a853089479b60b829bab1c4a0a737a073415f8a7
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Feb 8 21:53:09 2021 +0100
patch 8.2.2488: json_encode() gives generic argument error
Problem: json_encode() gives generic argument error.
Solution: Mention the type that can't be encoded. (issue https://github.com/vim/vim/issues/7802)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 08 Feb 2021 22:00:03 +0100 |
parents | 57c71d51e937 |
children | ca2346d6d6f1 |
files | src/errors.h src/json.c src/testdir/test_json.vim src/version.c |
diffstat | 4 files changed, 9 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/errors.h +++ b/src/errors.h @@ -357,3 +357,5 @@ EXTERN char e_cannot_split_window_when_c INIT(= N_("E1159: Cannot split a window when closing the buffer")); EXTERN char e_cannot_use_default_for_variable_arguments[] INIT(= N_("E1160: Cannot use a default for variable arguments")); +EXTERN char e_cannot_json_encode_str[] + INIT(= N_("E1161: Cannot json encode a %s"));
--- a/src/json.c +++ b/src/json.c @@ -230,8 +230,7 @@ json_encode_item(garray_T *gap, typval_T case VAR_PARTIAL: case VAR_JOB: case VAR_CHANNEL: - // no JSON equivalent TODO: better error - emsg(_(e_invarg)); + semsg(_(e_cannot_json_encode_str), vartype_name(val->v_type)); return FAIL; case VAR_BLOB:
--- a/src/testdir/test_json.vim +++ b/src/testdir/test_json.vim @@ -107,8 +107,8 @@ func Test_json_encode() call assert_equal('"café"', json_encode("caf\xe9")) let &encoding = save_encoding - call assert_fails('echo json_encode(function("tr"))', 'E474:') - call assert_fails('echo json_encode([function("tr")])', 'E474:') + call assert_fails('echo json_encode(function("tr"))', 'E1161: Cannot json encode a func') + call assert_fails('echo json_encode([function("tr")])', 'E1161: Cannot json encode a func') call assert_equal('{"a":""}', json_encode({'a': test_null_string()})) call assert_equal('{"a":[]}', json_encode({"a": test_null_list()})) @@ -246,8 +246,8 @@ func Test_js_encode() call assert_equal(s:jsonvals, js_encode(s:varvals)) - call assert_fails('echo js_encode(function("tr"))', 'E474:') - call assert_fails('echo js_encode([function("tr")])', 'E474:') + call assert_fails('echo js_encode(function("tr"))', 'E1161: Cannot json encode a func') + call assert_fails('echo js_encode([function("tr")])', 'E1161: Cannot json encode a func') silent! let res = js_encode(function("tr")) call assert_equal("", res)