Skip to content

Commit de9eb1d

Browse files
committed
Stop including the parser source __LINE__ in exceptions
It makes testing for JSON errors very tedious. You either have to use a Regexp or to regularly update all your assertions when JSON is upgraded.
1 parent 75ada77 commit de9eb1d

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

ext/json/ext/generator/generator.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,10 +997,10 @@ static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_St
997997
if (!allow_nan) {
998998
if (isinf(value)) {
999999
fbuffer_free(buffer);
1000-
rb_raise(eGeneratorError, "%u: %"PRIsVALUE" not allowed in JSON", __LINE__, RB_OBJ_STRING(tmp));
1000+
rb_raise(eGeneratorError, "%"PRIsVALUE" not allowed in JSON", RB_OBJ_STRING(tmp));
10011001
} else if (isnan(value)) {
10021002
fbuffer_free(buffer);
1003-
rb_raise(eGeneratorError, "%u: %"PRIsVALUE" not allowed in JSON", __LINE__, RB_OBJ_STRING(tmp));
1003+
rb_raise(eGeneratorError, "%"PRIsVALUE" not allowed in JSON", RB_OBJ_STRING(tmp));
10041004
}
10051005
}
10061006
fbuffer_append_str(buffer, tmp);

ext/json/ext/parser/parser.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
948948

949949
{p = p - 1; } {p+= 1; cs = 29; goto _out;}
950950
} else {
951-
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
951+
rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
952952
}
953953
}
954954
np = JSON_parse_float(json, p, pe, result);
@@ -990,7 +990,7 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
990990
if (json->allow_nan) {
991991
*result = CInfinity;
992992
} else {
993-
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
993+
rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p - 8);
994994
}
995995
}
996996

@@ -1002,7 +1002,7 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
10021002
if (json->allow_nan) {
10031003
*result = CNaN;
10041004
} else {
1005-
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
1005+
rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p - 2);
10061006
}
10071007
}
10081008

@@ -2348,7 +2348,7 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
23482348
if(cs >= JSON_array_first_final) {
23492349
return p + 1;
23502350
} else {
2351-
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
2351+
rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
23522352
return NULL;
23532353
}
23542354
}
@@ -2405,7 +2405,7 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int
24052405
}
24062406
rb_enc_raise(
24072407
EXC_ENCODING eParserError,
2408-
"%u: incomplete unicode character escape sequence at '%s'", __LINE__, p
2408+
"incomplete unicode character escape sequence at '%s'", p
24092409
);
24102410
} else {
24112411
UTF32 ch = unescape_unicode((unsigned char *) ++pe);
@@ -2418,7 +2418,7 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int
24182418
}
24192419
rb_enc_raise(
24202420
EXC_ENCODING eParserError,
2421-
"%u: incomplete surrogate pair at '%s'", __LINE__, p
2421+
"incomplete surrogate pair at '%s'", p
24222422
);
24232423
}
24242424
if (pe[0] == '\\' && pe[1] == 'u') {
@@ -3217,7 +3217,7 @@ static VALUE cParser_parse(VALUE self)
32173217
if (cs >= JSON_first_final && p == pe) {
32183218
return result;
32193219
} else {
3220-
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
3220+
rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
32213221
return Qnil;
32223222
}
32233223
}

ext/json/ext/parser/parser.rl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
222222
if (json->allow_nan) {
223223
*result = CNaN;
224224
} else {
225-
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
225+
rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p - 2);
226226
}
227227
}
228228
action parse_infinity {
229229
if (json->allow_nan) {
230230
*result = CInfinity;
231231
} else {
232-
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
232+
rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p - 8);
233233
}
234234
}
235235
action parse_string {
@@ -245,7 +245,7 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
245245
fexec p + 10;
246246
fhold; fbreak;
247247
} else {
248-
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
248+
rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
249249
}
250250
}
251251
np = JSON_parse_float(json, fpc, pe, result);
@@ -447,7 +447,7 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
447447
if(cs >= JSON_array_first_final) {
448448
return p + 1;
449449
} else {
450-
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
450+
rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
451451
return NULL;
452452
}
453453
}
@@ -504,7 +504,7 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int
504504
}
505505
rb_enc_raise(
506506
EXC_ENCODING eParserError,
507-
"%u: incomplete unicode character escape sequence at '%s'", __LINE__, p
507+
"incomplete unicode character escape sequence at '%s'", p
508508
);
509509
} else {
510510
UTF32 ch = unescape_unicode((unsigned char *) ++pe);
@@ -517,7 +517,7 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int
517517
}
518518
rb_enc_raise(
519519
EXC_ENCODING eParserError,
520-
"%u: incomplete surrogate pair at '%s'", __LINE__, p
520+
"incomplete surrogate pair at '%s'", p
521521
);
522522
}
523523
if (pe[0] == '\\' && pe[1] == 'u') {
@@ -856,7 +856,7 @@ static VALUE cParser_parse(VALUE self)
856856
if (cs >= JSON_first_final && p == pe) {
857857
return result;
858858
} else {
859-
rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
859+
rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
860860
return Qnil;
861861
}
862862
}

0 commit comments

Comments
 (0)