From aa6f39e43e9d542cb9796418b05ccc9d3ed99ce9 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 | 2 ++ 2 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..fc7dea5f420ac2 100644 --- a/ext/json/parser/parser.c +++ b/ext/json/parser/parser.c @@ -2098,6 +2098,8 @@ 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) {