Mercurial > vim
comparison src/json.c @ 20492:947e50e438d3 v8.2.0800
patch 8.2.0800: errors from failing test are unclear
Commit: https://github.com/vim/vim/commit/a09195f29ee8cd88411152cf311f4e4ab2f3b4b3
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue May 19 22:38:59 2020 +0200
patch 8.2.0800: errors from failing test are unclear
Problem: Errors from failing test are unclear.
Solution: Include text where parsing failed.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 19 May 2020 22:45:03 +0200 |
parents | 4c317d8c1051 |
children | 9064044fd4f6 |
comparison
equal
deleted
inserted
replaced
20491:5adb36b48d85 | 20492:947e50e438d3 |
---|---|
17 #include "vim.h" | 17 #include "vim.h" |
18 | 18 |
19 #if defined(FEAT_EVAL) || defined(PROTO) | 19 #if defined(FEAT_EVAL) || defined(PROTO) |
20 | 20 |
21 static int json_encode_item(garray_T *gap, typval_T *val, int copyID, int options); | 21 static int json_encode_item(garray_T *gap, typval_T *val, int copyID, int options); |
22 | |
23 static char e_json_error[] = N_("E491: json decode error at '%s'"); | |
22 | 24 |
23 /* | 25 /* |
24 * Encode "val" into a JSON format string. | 26 * Encode "val" into a JSON format string. |
25 * The result is added to "gap" | 27 * The result is added to "gap" |
26 * Returns FAIL on failure and makes gap->ga_data empty. | 28 * Returns FAIL on failure and makes gap->ga_data empty. |
738 case '\'': | 740 case '\'': |
739 if (options & JSON_JS) | 741 if (options & JSON_JS) |
740 retval = json_decode_string(reader, cur_item, *p); | 742 retval = json_decode_string(reader, cur_item, *p); |
741 else | 743 else |
742 { | 744 { |
743 emsg(_(e_invarg)); | 745 semsg(_(e_json_error), p); |
744 retval = FAIL; | 746 retval = FAIL; |
745 } | 747 } |
746 break; | 748 break; |
747 | 749 |
748 case ',': // comma: empty item | 750 case ',': // comma: empty item |
749 if ((options & JSON_JS) == 0) | 751 if ((options & JSON_JS) == 0) |
750 { | 752 { |
751 emsg(_(e_invarg)); | 753 semsg(_(e_json_error), p); |
752 retval = FAIL; | 754 retval = FAIL; |
753 break; | 755 break; |
754 } | 756 } |
755 // FALLTHROUGH | 757 // FALLTHROUGH |
756 case NUL: // empty | 758 case NUL: // empty |
776 retval = MAYBE; | 778 retval = MAYBE; |
777 break; | 779 break; |
778 } | 780 } |
779 if (!VIM_ISDIGIT(*sp)) | 781 if (!VIM_ISDIGIT(*sp)) |
780 { | 782 { |
781 emsg(_(e_invarg)); | 783 semsg(_(e_json_error), p); |
782 retval = FAIL; | 784 retval = FAIL; |
783 break; | 785 break; |
784 } | 786 } |
785 } | 787 } |
786 sp = skipdigits(sp); | 788 sp = skipdigits(sp); |
807 vim_str2nr(reader->js_buf + reader->js_used, | 809 vim_str2nr(reader->js_buf + reader->js_used, |
808 NULL, &len, 0, // what | 810 NULL, &len, 0, // what |
809 &nr, NULL, 0, TRUE); | 811 &nr, NULL, 0, TRUE); |
810 if (len == 0) | 812 if (len == 0) |
811 { | 813 { |
812 emsg(_(e_invarg)); | 814 semsg(_(e_json_error), p); |
813 retval = FAIL; | 815 retval = FAIL; |
814 goto theend; | 816 goto theend; |
815 } | 817 } |
816 if (cur_item != NULL) | 818 if (cur_item != NULL) |
817 { | 819 { |
960 { | 962 { |
961 if (*p == NUL) | 963 if (*p == NUL) |
962 retval = MAYBE; | 964 retval = MAYBE; |
963 else | 965 else |
964 { | 966 { |
965 emsg(_(e_invarg)); | 967 semsg(_(e_json_error), p); |
966 retval = FAIL; | 968 retval = FAIL; |
967 } | 969 } |
968 goto theend; | 970 goto theend; |
969 } | 971 } |
970 break; | 972 break; |
978 clear_tv(cur_item); | 980 clear_tv(cur_item); |
979 if (*p == NUL) | 981 if (*p == NUL) |
980 retval = MAYBE; | 982 retval = MAYBE; |
981 else | 983 else |
982 { | 984 { |
983 emsg(_(e_invarg)); | 985 semsg(_(e_json_error), p); |
984 retval = FAIL; | 986 retval = FAIL; |
985 } | 987 } |
986 goto theend; | 988 goto theend; |
987 } | 989 } |
988 ++reader->js_used; | 990 ++reader->js_used; |
1034 { | 1036 { |
1035 if (*p == NUL) | 1037 if (*p == NUL) |
1036 retval = MAYBE; | 1038 retval = MAYBE; |
1037 else | 1039 else |
1038 { | 1040 { |
1039 emsg(_(e_invarg)); | 1041 semsg(_(e_json_error), p); |
1040 retval = FAIL; | 1042 retval = FAIL; |
1041 } | 1043 } |
1042 goto theend; | 1044 goto theend; |
1043 } | 1045 } |
1044 top_item->jd_type = JSON_OBJECT_KEY; | 1046 top_item->jd_type = JSON_OBJECT_KEY; |
1053 { | 1055 { |
1054 clear_tv(res); | 1056 clear_tv(res); |
1055 res->v_type = VAR_SPECIAL; | 1057 res->v_type = VAR_SPECIAL; |
1056 res->vval.v_number = VVAL_NONE; | 1058 res->vval.v_number = VVAL_NONE; |
1057 } | 1059 } |
1058 emsg(_(e_invarg)); | 1060 semsg(_(e_json_error), p); |
1059 | 1061 |
1060 theend: | 1062 theend: |
1061 ga_clear(&stack); | 1063 ga_clear(&stack); |
1062 return retval; | 1064 return retval; |
1063 } | 1065 } |
1077 json_skip_white(reader); | 1079 json_skip_white(reader); |
1078 ret = json_decode_item(reader, res, options); | 1080 ret = json_decode_item(reader, res, options); |
1079 if (ret != OK) | 1081 if (ret != OK) |
1080 { | 1082 { |
1081 if (ret == MAYBE) | 1083 if (ret == MAYBE) |
1082 emsg(_(e_invarg)); | 1084 semsg(_(e_json_error), reader->js_buf); |
1083 return FAIL; | 1085 return FAIL; |
1084 } | 1086 } |
1085 json_skip_white(reader); | 1087 json_skip_white(reader); |
1086 if (reader->js_buf[reader->js_used] != NUL) | 1088 if (reader->js_buf[reader->js_used] != NUL) |
1087 { | 1089 { |