@@ -1017,8 +1017,10 @@ type_caster<T, SFINAE> &load_type(type_caster<T, SFINAE> &conv, const handle &ha
1017
1017
" Internal error: type_caster should only be used for C++ types" );
1018
1018
if (!conv.load (handle, true )) {
1019
1019
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1020
- throw cast_error (" Unable to cast Python instance to C++ type (#define "
1021
- " PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)" );
1020
+ throw cast_error (
1021
+ " Unable to cast Python instance of type " + static_cast <std::string>(str (type::handle_of (handle)))
1022
+ + " to C++ type '?' (#define "
1023
+ " PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)" );
1022
1024
#else
1023
1025
throw cast_error (" Unable to cast Python instance of type "
1024
1026
+ (std::string) str (type::handle_of (handle)) + " to C++ type '"
@@ -1085,8 +1087,9 @@ detail::enable_if_t<!detail::move_never<T>::value, T> move(object &&obj) {
1085
1087
if (obj.ref_count () > 1 ) {
1086
1088
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1087
1089
throw cast_error (
1088
- " Unable to cast Python instance to C++ rvalue: instance has multiple references"
1089
- " (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)" );
1090
+ " Unable to cast Python " + (std::string) str (type::handle_of (obj))
1091
+ + " instance to C++ rvalue: instance has multiple references"
1092
+ " (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)" );
1090
1093
#else
1091
1094
throw cast_error (" Unable to move from Python " + (std::string) str (type::handle_of (obj))
1092
1095
+ " instance to C++ " + type_id<T>()
@@ -1195,9 +1198,10 @@ PYBIND11_NAMESPACE_END(detail)
1195
1198
// The overloads could coexist, i.e. the #if is not strictly speaking needed,
1196
1199
// but it is an easy minor optimization.
1197
1200
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1198
- inline cast_error cast_error_unable_to_convert_call_arg () {
1199
- return cast_error (" Unable to convert call argument to Python object (#define "
1200
- " PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)" );
1201
+ inline cast_error cast_error_unable_to_convert_call_arg (const std::string &name) {
1202
+ return cast_error (" Unable to convert call argument '" + name
1203
+ + " ' to Python object (#define "
1204
+ " PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)" );
1201
1205
}
1202
1206
#else
1203
1207
inline cast_error cast_error_unable_to_convert_call_arg (const std::string &name,
@@ -1220,7 +1224,7 @@ tuple make_tuple(Args &&...args_) {
1220
1224
for (size_t i = 0 ; i < args.size (); i++) {
1221
1225
if (!args[i]) {
1222
1226
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1223
- throw cast_error_unable_to_convert_call_arg ();
1227
+ throw cast_error_unable_to_convert_call_arg (std::to_string (i) );
1224
1228
#else
1225
1229
std::array<std::string, size> argtypes{{type_id<Args>()...}};
1226
1230
throw cast_error_unable_to_convert_call_arg (std::to_string (i), argtypes[i]);
@@ -1510,7 +1514,7 @@ class unpacking_collector {
1510
1514
detail::make_caster<T>::cast (std::forward<T>(x), policy, {}));
1511
1515
if (!o) {
1512
1516
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1513
- throw cast_error_unable_to_convert_call_arg ();
1517
+ throw cast_error_unable_to_convert_call_arg (std::to_string (args_list. size ()) );
1514
1518
#else
1515
1519
throw cast_error_unable_to_convert_call_arg (std::to_string (args_list.size ()),
1516
1520
type_id<T>());
@@ -1542,7 +1546,7 @@ class unpacking_collector {
1542
1546
}
1543
1547
if (!a.value ) {
1544
1548
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1545
- throw cast_error_unable_to_convert_call_arg ();
1549
+ throw cast_error_unable_to_convert_call_arg (a. name );
1546
1550
#else
1547
1551
throw cast_error_unable_to_convert_call_arg (a.name , a.type );
1548
1552
#endif
0 commit comments