@@ -69,13 +69,11 @@ static VALUE rb_fast_jsonparser_parse(VALUE self, VALUE arg)
69
69
70
70
dom::parser parser;
71
71
auto [doc, error] = parser.parse (RSTRING_PTR (arg), RSTRING_LEN (arg));
72
- if (error = = SUCCESS)
72
+ if (error ! = SUCCESS)
73
73
{
74
- return make_ruby_object (doc );
74
+ rb_raise (rb_eFastJsonparserParseError, " %s " , error_message (error) );
75
75
}
76
- // TODO better error handling
77
- rb_raise (rb_eFastJsonparserParseError, " parse error" );
78
- return Qnil;
76
+ return make_ruby_object (doc);
79
77
}
80
78
81
79
static VALUE rb_fast_jsonparser_load (VALUE self, VALUE arg)
@@ -84,13 +82,11 @@ static VALUE rb_fast_jsonparser_load(VALUE self, VALUE arg)
84
82
85
83
dom::parser parser;
86
84
auto [doc, error] = parser.load (RSTRING_PTR (arg));
87
- if (error = = SUCCESS)
85
+ if (error ! = SUCCESS)
88
86
{
89
- return make_ruby_object (doc );
87
+ rb_raise (rb_eFastJsonparserParseError, " %s " , error_message (error) );
90
88
}
91
- // TODO better error handling
92
- rb_raise (rb_eFastJsonparserParseError, " parse error" );
93
- return Qnil;
89
+ return make_ruby_object (doc);
94
90
}
95
91
96
92
static VALUE rb_fast_jsonparser_load_many (VALUE self, VALUE arg, VALUE batch_size)
@@ -101,15 +97,16 @@ static VALUE rb_fast_jsonparser_load_many(VALUE self, VALUE arg, VALUE batch_siz
101
97
try {
102
98
dom::parser parser;
103
99
auto [docs, error] = parser.load_many (RSTRING_PTR (arg), FIX2INT (batch_size));
104
- if (error = = SUCCESS)
100
+ if (error ! = SUCCESS)
105
101
{
106
- for (dom::element doc : docs)
107
- {
108
- rb_yield (make_ruby_object (doc));
109
- }
110
- return Qnil;
102
+ rb_raise (rb_eFastJsonparserParseError, " %s" , error_message (error));
111
103
}
112
- rb_raise (rb_eFastJsonparserParseError, " parse error" );
104
+
105
+ for (dom::element doc : docs)
106
+ {
107
+ rb_yield (make_ruby_object (doc));
108
+ }
109
+
113
110
return Qnil;
114
111
} catch (simdjson::simdjson_error error) {
115
112
rb_raise (rb_eFastJsonparserUnknownError, " %s" , error.what ());
0 commit comments