diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-02-08 21:53:09 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-02-08 21:53:09 +0100 |
commit | a853089479b60b829bab1c4a0a737a073415f8a7 (patch) | |
tree | c05ab6242a7301a31adbb0e2021aa09fc775ad8b | |
parent | 4549dad874244fe933b969e4ac0b41923ee70dc3 (diff) | |
download | vim-git-a853089479b60b829bab1c4a0a737a073415f8a7.tar.gz |
patch 8.2.2488: json_encode() gives generic argument errorv8.2.2488
Problem: json_encode() gives generic argument error.
Solution: Mention the type that can't be encoded. (issue #7802)
-rw-r--r-- | src/errors.h | 2 | ||||
-rw-r--r-- | src/json.c | 3 | ||||
-rw-r--r-- | src/testdir/test_json.vim | 8 | ||||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 9 insertions, 6 deletions
diff --git a/src/errors.h b/src/errors.h index 9b9a78275..aaf7e552c 100644 --- a/src/errors.h +++ b/src/errors.h @@ -357,3 +357,5 @@ EXTERN char e_cannot_split_window_when_closing_buffer[] 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")); diff --git a/src/json.c b/src/json.c index 8262640db..dba003eae 100644 --- a/src/json.c +++ b/src/json.c @@ -230,8 +230,7 @@ json_encode_item(garray_T *gap, typval_T *val, int copyID, int options) 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: diff --git a/src/testdir/test_json.vim b/src/testdir/test_json.vim index 29585ca21..0248aa9ec 100644 --- 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) diff --git a/src/version.c b/src/version.c index d07c0e3ee..8b5de13e1 100644 --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2488, +/**/ 2487, /**/ 2486, |