]> granicus.if.org Git - vim/commitdiff
patch 8.2.2488: json_encode() gives generic argument error v8.2.2488
authorBram Moolenaar <Bram@vim.org>
Mon, 8 Feb 2021 20:53:09 +0000 (21:53 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 8 Feb 2021 20:53:09 +0000 (21:53 +0100)
Problem:    json_encode() gives generic argument error.
Solution:   Mention the type that can't be encoded. (issue #7802)

src/errors.h
src/json.c
src/testdir/test_json.vim
src/version.c

index 9b9a7827537c2b7c5032c4f4a9ac700d87731b24..aaf7e552c9b830c52919de3d45d7318580ae70c4 100644 (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"));
 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"));
index 8262640db896d9b4fdc760f4370bbdb61f2b3bbb..dba003eae78a1e18fb9fe809b0bb5b6f122b55b1 100644 (file)
@@ -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:
index 29585ca21f325a04f39cccd76f7a4ed89811ea81..0248aa9ecced194289effa1fdc4cc7f0583a25d0 100644 (file)
@@ -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)
index d07c0e3eecfe640b0ab044ed9678abc55a31c2ff..8b5de13e126067a038c607631db0bfc143ecf093 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2488,
 /**/
     2487,
 /**/