0
0
mirror of https://github.com/vim/vim.git synced 2025-09-29 04:34:16 -04:00

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 #7802)
This commit is contained in:
Bram Moolenaar
2021-02-08 21:53:09 +01:00
parent 4549dad874
commit a853089479
4 changed files with 9 additions and 6 deletions

View File

@@ -357,3 +357,5 @@ EXTERN char e_cannot_split_window_when_closing_buffer[]
INIT(= N_("E1159: Cannot split a window when closing the buffer")); INIT(= N_("E1159: Cannot split a window when closing the buffer"));
EXTERN char e_cannot_use_default_for_variable_arguments[] EXTERN char e_cannot_use_default_for_variable_arguments[]
INIT(= N_("E1160: Cannot use a 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"));

View File

@@ -230,8 +230,7 @@ json_encode_item(garray_T *gap, typval_T *val, int copyID, int options)
case VAR_PARTIAL: case VAR_PARTIAL:
case VAR_JOB: case VAR_JOB:
case VAR_CHANNEL: case VAR_CHANNEL:
// no JSON equivalent TODO: better error semsg(_(e_cannot_json_encode_str), vartype_name(val->v_type));
emsg(_(e_invarg));
return FAIL; return FAIL;
case VAR_BLOB: case VAR_BLOB:

View File

@@ -107,8 +107,8 @@ func Test_json_encode()
call assert_equal('"café"', json_encode("caf\xe9")) call assert_equal('"café"', json_encode("caf\xe9"))
let &encoding = save_encoding let &encoding = save_encoding
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")])', 'E474:') 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_string()}))
call assert_equal('{"a":[]}', json_encode({"a": test_null_list()})) 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_equal(s:jsonvals, js_encode(s:varvals))
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")])', 'E474:') call assert_fails('echo js_encode([function("tr")])', 'E1161: Cannot json encode a func')
silent! let res = js_encode(function("tr")) silent! let res = js_encode(function("tr"))
call assert_equal("", res) call assert_equal("", res)

View File

@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
2488,
/**/ /**/
2487, 2487,
/**/ /**/