From bb83715f0095809fca2853c0579ab6ec27d2b213 Mon Sep 17 00:00:00 2001 From: Bruno Gomes Date: Tue, 23 Jun 2020 12:21:51 -0300 Subject: [PATCH] Improve documentation for JSON#parse Adds information about raised error when fail to parse --- ext/json/lib/json/common.rb | 2 ++ ext/json/parser/parser.c | 1 + ext/json/parser/parser.rl | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ext/json/lib/json/common.rb b/ext/json/lib/json/common.rb index f44184e138bb16..2b111c44e464b3 100644 --- a/ext/json/lib/json/common.rb +++ b/ext/json/lib/json/common.rb @@ -134,6 +134,7 @@ class MissingUnicodeSupport < JSONError; end module_function # Parse the JSON document _source_ into a Ruby data structure and return it. + # It raises JSON::ParserError if it fails to parse. # # _opts_ can have the following # keys: @@ -158,6 +159,7 @@ def parse(source, opts = {}) # Parse the JSON document _source_ into a Ruby data structure and return it. # The bang version of the parse method defaults to the more dangerous values # for the _opts_ hash, so be sure only to parse trusted _source_ documents. + # It raises JSON::ParserError if it fails to parse. # # _opts_ can have the following keys: # * *max_nesting*: The maximum depth of nesting allowed in the parsed data diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c index ae9be78ec26898..e3d47e3a810c11 100644 --- a/ext/json/parser/parser.c +++ b/ext/json/parser/parser.c @@ -2098,6 +2098,7 @@ case 9: * * Parses the current JSON text _source_ and returns the complete data * structure as a result. + * It raises JSON::ParseError if fail to parse. */ static VALUE cParser_parse(VALUE self) { diff --git a/ext/json/parser/parser.rl b/ext/json/parser/parser.rl index 327e08cd81f2fa..6b46e8a49d3f05 100644 --- a/ext/json/parser/parser.rl +++ b/ext/json/parser/parser.rl @@ -820,7 +820,8 @@ static VALUE cParser_parse_quirks_mode(VALUE self) * call-seq: parse() * * Parses the current JSON text _source_ and returns the complete data - * structure as a result. + * structure as a result.A + * It raises JSON::ParseError if fail to parse. */ static VALUE cParser_parse(VALUE self) {