Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error 305 #1221

Merged
merged 3 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())));
}

/*!
Expand Down Expand Up @@ -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())));
}

/*!
Expand Down Expand Up @@ -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())));
}

/*!
Expand Down Expand Up @@ -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())));
}

/*!
Expand Down Expand Up @@ -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())));
}

/*!
Expand Down Expand Up @@ -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())));
}

/*!
Expand Down
12 changes: 6 additions & 6 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14204,7 +14204,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())));
}

/*!
Expand Down Expand Up @@ -14234,7 +14234,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())));
}

/*!
Expand Down Expand Up @@ -14280,7 +14280,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())));
}

/*!
Expand Down Expand Up @@ -14322,7 +14322,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())));
}

/*!
Expand Down Expand Up @@ -14369,7 +14369,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())));
}

/*!
Expand Down Expand Up @@ -14412,7 +14412,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())));
}

/*!
Expand Down
26 changes: 13 additions & 13 deletions test/src/unit-element_access1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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)")
Expand All @@ -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)")
Expand All @@ -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)")
Expand All @@ -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");
}
}
}
Expand Down
Loading