From 5116e2a6bfbc12ab0a6eac66e159a01d393588de 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 | 1 + 3 files changed, 4 insertions(+) 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..2e6d024969e010 100644 --- a/ext/json/parser/parser.rl +++ b/ext/json/parser/parser.rl @@ -821,6 +821,7 @@ static VALUE cParser_parse_quirks_mode(VALUE self) * * 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) {