Unverified Commit 7fa3b886 by Niels Lohmann Committed by GitHub

Merge pull request #1221 from rivertam/better-error-305

Better error 305
parents 186c747a 8f07ab63
......@@ -3097,7 +3097,7 @@ class basic_json
return m_value.array->operator[](idx);
}
JSON_THROW(type_error::create(305, "cannot use operator[] with " + std::string(type_name())));
JSON_THROW(type_error::create(305, "cannot use operator[] with a numeric argument with " + std::string(type_name())));
}
/*!
......@@ -3127,7 +3127,7 @@ class basic_json
return m_value.array->operator[](idx);
}
JSON_THROW(type_error::create(305, "cannot use operator[] with " + std::string(type_name())));
JSON_THROW(type_error::create(305, "cannot use operator[] with a numeric argument with " + std::string(type_name())));
}
/*!
......@@ -3173,7 +3173,7 @@ class basic_json
return m_value.object->operator[](key);
}
JSON_THROW(type_error::create(305, "cannot use operator[] with " + std::string(type_name())));
JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name())));
}
/*!
......@@ -3215,7 +3215,7 @@ class basic_json
return m_value.object->find(key)->second;
}
JSON_THROW(type_error::create(305, "cannot use operator[] with " + std::string(type_name())));
JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name())));
}
/*!
......@@ -3262,7 +3262,7 @@ class basic_json
return m_value.object->operator[](key);
}
JSON_THROW(type_error::create(305, "cannot use operator[] with " + std::string(type_name())));
JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name())));
}
/*!
......@@ -3305,7 +3305,7 @@ class basic_json
return m_value.object->find(key)->second;
}
JSON_THROW(type_error::create(305, "cannot use operator[] with " + std::string(type_name())));
JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name())));
}
/*!
......
......@@ -14170,7 +14170,7 @@ class basic_json
return m_value.array->operator[](idx);
}
JSON_THROW(type_error::create(305, "cannot use operator[] with " + std::string(type_name())));
JSON_THROW(type_error::create(305, "cannot use operator[] with a numeric argument with " + std::string(type_name())));
}
/*!
......@@ -14200,7 +14200,7 @@ class basic_json
return m_value.array->operator[](idx);
}
JSON_THROW(type_error::create(305, "cannot use operator[] with " + std::string(type_name())));
JSON_THROW(type_error::create(305, "cannot use operator[] with a numeric argument with " + std::string(type_name())));
}
/*!
......@@ -14246,7 +14246,7 @@ class basic_json
return m_value.object->operator[](key);
}
JSON_THROW(type_error::create(305, "cannot use operator[] with " + std::string(type_name())));
JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name())));
}
/*!
......@@ -14288,7 +14288,7 @@ class basic_json
return m_value.object->find(key)->second;
}
JSON_THROW(type_error::create(305, "cannot use operator[] with " + std::string(type_name())));
JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name())));
}
/*!
......@@ -14335,7 +14335,7 @@ class basic_json
return m_value.object->operator[](key);
}
JSON_THROW(type_error::create(305, "cannot use operator[] with " + std::string(type_name())));
JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name())));
}
/*!
......@@ -14378,7 +14378,7 @@ class basic_json
return m_value.object->find(key)->second;
}
JSON_THROW(type_error::create(305, "cannot use operator[] with " + std::string(type_name())));
JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name())));
}
/*!
......
......@@ -195,7 +195,7 @@ TEST_CASE("element access 1")
const json j_nonarray_const(j_nonarray);
CHECK_NOTHROW(j_nonarray[0]);
CHECK_THROWS_AS(j_nonarray_const[0], json::type_error&);
CHECK_THROWS_WITH(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with null");
CHECK_THROWS_WITH(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with null");
}
SECTION("implicit transformation to properly filled array")
......@@ -212,8 +212,8 @@ TEST_CASE("element access 1")
const json j_nonarray_const(j_nonarray);
CHECK_THROWS_AS(j_nonarray[0], json::type_error&);
CHECK_THROWS_AS(j_nonarray_const[0], json::type_error&);
CHECK_THROWS_WITH(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with boolean");
CHECK_THROWS_WITH(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with boolean");
CHECK_THROWS_WITH(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with boolean");
CHECK_THROWS_WITH(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with boolean");
}
SECTION("string")
......@@ -222,8 +222,8 @@ TEST_CASE("element access 1")
const json j_nonarray_const(j_nonarray);
CHECK_THROWS_AS(j_nonarray[0], json::type_error&);
CHECK_THROWS_AS(j_nonarray_const[0], json::type_error&);
CHECK_THROWS_WITH(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with string");
CHECK_THROWS_WITH(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with string");
CHECK_THROWS_WITH(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with string");
CHECK_THROWS_WITH(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with string");
}
SECTION("object")
......@@ -232,8 +232,8 @@ TEST_CASE("element access 1")
const json j_nonarray_const(j_nonarray);
CHECK_THROWS_AS(j_nonarray[0], json::type_error&);
CHECK_THROWS_AS(j_nonarray_const[0], json::type_error&);
CHECK_THROWS_WITH(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with object");
CHECK_THROWS_WITH(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with object");
CHECK_THROWS_WITH(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with object");
CHECK_THROWS_WITH(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with object");
}
SECTION("number (integer)")
......@@ -242,8 +242,8 @@ TEST_CASE("element access 1")
const json j_nonarray_const(j_nonarray);
CHECK_THROWS_AS(j_nonarray[0], json::type_error&);
CHECK_THROWS_AS(j_nonarray_const[0], json::type_error&);
CHECK_THROWS_WITH(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with number");
CHECK_THROWS_WITH(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with number");
CHECK_THROWS_WITH(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number");
CHECK_THROWS_WITH(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number");
}
SECTION("number (unsigned)")
......@@ -252,8 +252,8 @@ TEST_CASE("element access 1")
const json j_nonarray_const(j_nonarray);
CHECK_THROWS_AS(j_nonarray[0], json::type_error&);
CHECK_THROWS_AS(j_nonarray_const[0], json::type_error&);
CHECK_THROWS_WITH(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with number");
CHECK_THROWS_WITH(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with number");
CHECK_THROWS_WITH(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number");
CHECK_THROWS_WITH(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number");
}
SECTION("number (floating-point)")
......@@ -262,8 +262,8 @@ TEST_CASE("element access 1")
const json j_nonarray_const(j_nonarray);
CHECK_THROWS_AS(j_nonarray[0], json::type_error&);
CHECK_THROWS_AS(j_nonarray_const[0], json::type_error&);
CHECK_THROWS_WITH(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with number");
CHECK_THROWS_WITH(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with number");
CHECK_THROWS_WITH(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number");
CHECK_THROWS_WITH(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number");
}
}
}
......
......@@ -475,9 +475,9 @@ TEST_CASE("element access 2")
CHECK_NOTHROW(j_nonobject2[json::object_t::key_type("foo")]);
CHECK_THROWS_AS(j_const_nonobject["foo"], json::type_error&);
CHECK_THROWS_AS(j_const_nonobject[json::object_t::key_type("foo")], json::type_error&);
CHECK_THROWS_WITH(j_const_nonobject["foo"], "[json.exception.type_error.305] cannot use operator[] with null");
CHECK_THROWS_WITH(j_const_nonobject["foo"], "[json.exception.type_error.305] cannot use operator[] with a string argument with null");
CHECK_THROWS_WITH(j_const_nonobject[json::object_t::key_type("foo")],
"[json.exception.type_error.305] cannot use operator[] with null");
"[json.exception.type_error.305] cannot use operator[] with a string argument with null");
}
SECTION("boolean")
......@@ -489,13 +489,13 @@ TEST_CASE("element access 2")
CHECK_THROWS_AS(j_const_nonobject["foo"], json::type_error&);
CHECK_THROWS_AS(j_const_nonobject[json::object_t::key_type("foo")], json::type_error&);
CHECK_THROWS_WITH(j_nonobject["foo"],
"[json.exception.type_error.305] cannot use operator[] with boolean");
"[json.exception.type_error.305] cannot use operator[] with a string argument with boolean");
CHECK_THROWS_WITH(j_nonobject[json::object_t::key_type("foo")],
"[json.exception.type_error.305] cannot use operator[] with boolean");
"[json.exception.type_error.305] cannot use operator[] with a string argument with boolean");
CHECK_THROWS_WITH(j_const_nonobject["foo"],
"[json.exception.type_error.305] cannot use operator[] with boolean");
"[json.exception.type_error.305] cannot use operator[] with a string argument with boolean");
CHECK_THROWS_WITH(j_const_nonobject[json::object_t::key_type("foo")],
"[json.exception.type_error.305] cannot use operator[] with boolean");
"[json.exception.type_error.305] cannot use operator[] with a string argument with boolean");
}
SECTION("string")
......@@ -507,13 +507,13 @@ TEST_CASE("element access 2")
CHECK_THROWS_AS(j_const_nonobject["foo"], json::type_error&);
CHECK_THROWS_AS(j_const_nonobject[json::object_t::key_type("foo")], json::type_error&);
CHECK_THROWS_WITH(j_nonobject["foo"],
"[json.exception.type_error.305] cannot use operator[] with string");
"[json.exception.type_error.305] cannot use operator[] with a string argument with string");
CHECK_THROWS_WITH(j_nonobject[json::object_t::key_type("foo")],
"[json.exception.type_error.305] cannot use operator[] with string");
"[json.exception.type_error.305] cannot use operator[] with a string argument with string");
CHECK_THROWS_WITH(j_const_nonobject["foo"],
"[json.exception.type_error.305] cannot use operator[] with string");
"[json.exception.type_error.305] cannot use operator[] with a string argument with string");
CHECK_THROWS_WITH(j_const_nonobject[json::object_t::key_type("foo")],
"[json.exception.type_error.305] cannot use operator[] with string");
"[json.exception.type_error.305] cannot use operator[] with a string argument with string");
}
SECTION("array")
......@@ -525,12 +525,12 @@ TEST_CASE("element access 2")
CHECK_THROWS_AS(j_const_nonobject["foo"], json::type_error&);
CHECK_THROWS_AS(j_const_nonobject[json::object_t::key_type("foo")], json::type_error&);
CHECK_THROWS_WITH(j_nonobject["foo"],
"[json.exception.type_error.305] cannot use operator[] with array");
CHECK_THROWS_WITH(j_nonobject[json::object_t::key_type("foo")], "[json.exception.type_error.305] cannot use operator[] with array");
"[json.exception.type_error.305] cannot use operator[] with a string argument with array");
CHECK_THROWS_WITH(j_nonobject[json::object_t::key_type("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with array");
CHECK_THROWS_WITH(j_const_nonobject["foo"],
"[json.exception.type_error.305] cannot use operator[] with array");
"[json.exception.type_error.305] cannot use operator[] with a string argument with array");
CHECK_THROWS_WITH(j_const_nonobject[json::object_t::key_type("foo")],
"[json.exception.type_error.305] cannot use operator[] with array");
"[json.exception.type_error.305] cannot use operator[] with a string argument with array");
}
SECTION("number (integer)")
......@@ -542,13 +542,13 @@ TEST_CASE("element access 2")
CHECK_THROWS_AS(j_const_nonobject["foo"], json::type_error&);
CHECK_THROWS_AS(j_const_nonobject[json::object_t::key_type("foo")], json::type_error&);
CHECK_THROWS_WITH(j_nonobject["foo"],
"[json.exception.type_error.305] cannot use operator[] with number");
"[json.exception.type_error.305] cannot use operator[] with a string argument with number");
CHECK_THROWS_WITH(j_nonobject[json::object_t::key_type("foo")],
"[json.exception.type_error.305] cannot use operator[] with number");
"[json.exception.type_error.305] cannot use operator[] with a string argument with number");
CHECK_THROWS_WITH(j_const_nonobject["foo"],
"[json.exception.type_error.305] cannot use operator[] with number");
"[json.exception.type_error.305] cannot use operator[] with a string argument with number");
CHECK_THROWS_WITH(j_const_nonobject[json::object_t::key_type("foo")],
"[json.exception.type_error.305] cannot use operator[] with number");
"[json.exception.type_error.305] cannot use operator[] with a string argument with number");
}
SECTION("number (unsigned)")
......@@ -560,13 +560,13 @@ TEST_CASE("element access 2")
CHECK_THROWS_AS(j_const_nonobject["foo"], json::type_error&);
CHECK_THROWS_AS(j_const_nonobject[json::object_t::key_type("foo")], json::type_error&);
CHECK_THROWS_WITH(j_nonobject["foo"],
"[json.exception.type_error.305] cannot use operator[] with number");
"[json.exception.type_error.305] cannot use operator[] with a string argument with number");
CHECK_THROWS_WITH(j_nonobject[json::object_t::key_type("foo")],
"[json.exception.type_error.305] cannot use operator[] with number");
"[json.exception.type_error.305] cannot use operator[] with a string argument with number");
CHECK_THROWS_WITH(j_const_nonobject["foo"],
"[json.exception.type_error.305] cannot use operator[] with number");
"[json.exception.type_error.305] cannot use operator[] with a string argument with number");
CHECK_THROWS_WITH(j_const_nonobject[json::object_t::key_type("foo")],
"[json.exception.type_error.305] cannot use operator[] with number");
"[json.exception.type_error.305] cannot use operator[] with a string argument with number");
}
SECTION("number (floating-point)")
......@@ -578,13 +578,13 @@ TEST_CASE("element access 2")
CHECK_THROWS_AS(j_const_nonobject["foo"], json::type_error&);
CHECK_THROWS_AS(j_const_nonobject[json::object_t::key_type("foo")], json::type_error&);
CHECK_THROWS_WITH(j_nonobject["foo"],
"[json.exception.type_error.305] cannot use operator[] with number");
"[json.exception.type_error.305] cannot use operator[] with a string argument with number");
CHECK_THROWS_WITH(j_nonobject[json::object_t::key_type("foo")],
"[json.exception.type_error.305] cannot use operator[] with number");
"[json.exception.type_error.305] cannot use operator[] with a string argument with number");
CHECK_THROWS_WITH(j_const_nonobject["foo"],
"[json.exception.type_error.305] cannot use operator[] with number");
"[json.exception.type_error.305] cannot use operator[] with a string argument with number");
CHECK_THROWS_WITH(j_const_nonobject[json::object_t::key_type("foo")],
"[json.exception.type_error.305] cannot use operator[] with number");
"[json.exception.type_error.305] cannot use operator[] with a string argument with number");
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment