From 54073332248e90de6b08ff7c5a3f1288205fc8f4 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 6 Mar 2017 22:37:46 +0100 Subject: [PATCH] :hammer: added user-defined exception 111 --- src/json.hpp | 4 ++-- src/json.hpp.re2c | 4 ++-- test/src/unit-regression.cpp | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index 6a36b85d6..5fc66dc56 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -173,7 +173,7 @@ json.exception.[parse_error](@ref parse_error).107 | "parse error: JSON pointer json.exception.[parse_error](@ref parse_error).108 | "parse error: escape character '~' must be followed with '0' or '1'" | In a JSON Pointer, only `~0` and `~1` are valid escape sequences. json.exception.[parse_error](@ref parse_error).109 | "parse error: array index 'one' is not a number" | A JSON Pointer array index must be a number. json.exception.[parse_error](@ref parse_error).110 | "parse error at 1: cannot read 2 bytes from vector" | When parsing CBOR or MessagePack, the byte vector ends before the complete value has been read. - +json.exception.[parse_error](@ref parse_error).111 | "parse error: bad input stream" | Parsing CBOR or MessagePack from an input stream where the `badbit` or `failbit` is set. @since version 3.0.0 */ @@ -9889,7 +9889,7 @@ class basic_json // immediately abort if stream is erroneous if (s.fail()) { - JSON_THROW(std::invalid_argument("stream error")); + JSON_THROW(parse_error(111, 0, "bad input stream")); } // fill buffer diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 4ee6cced6..d022375b8 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -173,7 +173,7 @@ json.exception.[parse_error](@ref parse_error).107 | "parse error: JSON pointer json.exception.[parse_error](@ref parse_error).108 | "parse error: escape character '~' must be followed with '0' or '1'" | In a JSON Pointer, only `~0` and `~1` are valid escape sequences. json.exception.[parse_error](@ref parse_error).109 | "parse error: array index 'one' is not a number" | A JSON Pointer array index must be a number. json.exception.[parse_error](@ref parse_error).110 | "parse error at 1: cannot read 2 bytes from vector" | When parsing CBOR or MessagePack, the byte vector ends before the complete value has been read. - +json.exception.[parse_error](@ref parse_error).111 | "parse error: bad input stream" | Parsing CBOR or MessagePack from an input stream where the `badbit` or `failbit` is set. @since version 3.0.0 */ @@ -9889,7 +9889,7 @@ class basic_json // immediately abort if stream is erroneous if (s.fail()) { - JSON_THROW(std::invalid_argument("stream error")); + JSON_THROW(parse_error(111, 0, "bad input stream")); } // fill buffer diff --git a/test/src/unit-regression.cpp b/test/src/unit-regression.cpp index 9dea8083b..2d7990676 100644 --- a/test/src/unit-regression.cpp +++ b/test/src/unit-regression.cpp @@ -565,7 +565,8 @@ TEST_CASE("regression tests") SECTION("issue #366 - json::parse on failed stream gets stuck") { std::ifstream f("file_not_found.json"); - CHECK_THROWS_AS(json::parse(f), std::invalid_argument); + CHECK_THROWS_AS(json::parse(f), json::parse_error); + CHECK_THROWS_WITH(json::parse(f), "[json.exception.parse_error.111] parse error: bad input stream"); } SECTION("issue #367 - calling stream at EOF") -- GitLab