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