Skip to content

Commit f5ff4bd

Browse files
committed
nicer error messages
1 parent a6eff77 commit f5ff4bd

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

ext/json/ext/generator/unicode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void JSON_convert_UTF8_to_JSON(VALUE buffer, VALUE string, ConversionFlags flags
113113
}
114114
if (!isLegalUTF8(source, extraBytesToRead+1)) {
115115
rb_raise(rb_path2class("JSON::GeneratorError"),
116-
"source sequence is illegal/malformed");
116+
"source sequence is illegal/malformed utf-8");
117117
}
118118
/*
119119
* The cases all fall through. See "Note A" below.
@@ -134,7 +134,7 @@ void JSON_convert_UTF8_to_JSON(VALUE buffer, VALUE string, ConversionFlags flags
134134
if (flags == strictConversion) {
135135
source -= (extraBytesToRead+1); /* return to the illegal value itself */
136136
rb_raise(rb_path2class("JSON::GeneratorError"),
137-
"source sequence is illegal/malformed");
137+
"source sequence is illegal/malformed utf-8");
138138
} else {
139139
unicode_escape(buffer, UNI_REPLACEMENT_CHAR);
140140
}
@@ -166,7 +166,7 @@ void JSON_convert_UTF8_to_JSON(VALUE buffer, VALUE string, ConversionFlags flags
166166
if (flags == strictConversion) {
167167
source -= (extraBytesToRead+1); /* return to the start */
168168
rb_raise(rb_path2class("JSON::GeneratorError"),
169-
"source sequence is illegal/malformed");
169+
"source sequence is illegal/malformed utf8");
170170
} else {
171171
unicode_escape(buffer, UNI_REPLACEMENT_CHAR);
172172
}

ext/json/ext/parser/unicode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ char *JSON_convert_UTF16_to_UTF8 (
105105
} else if (flags == strictConversion) { /* it's an unpaired high surrogate */
106106
ruby_xfree(tmp);
107107
rb_raise(rb_path2class("JSON::ParserError"),
108-
"source sequence is illegal/malformed near %s", source);
108+
"\\uXXXX is illegal/malformed utf-16 near %s", source);
109109
}
110110
} else { /* We don't have the 16 bits following the high surrogate. */
111111
ruby_xfree(tmp);
@@ -118,7 +118,7 @@ char *JSON_convert_UTF16_to_UTF8 (
118118
if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END) {
119119
ruby_xfree(tmp);
120120
rb_raise(rb_path2class("JSON::ParserError"),
121-
"source sequence is illegal/malformed near %s", source);
121+
"\\uXXXX is illegal/malformed utf-16 near %s", source);
122122
}
123123
}
124124
/* Figure out how many bytes the result will require */

0 commit comments

Comments
 (0)