@@ -1059,7 +1059,8 @@ make_caster_for_intrinsic<T> &load_type(make_caster_for_intrinsic<T> &conv, cons
1059
1059
" Internal error: type_caster should only be used for C++ types" );
1060
1060
if (!conv.load (handle, true )) {
1061
1061
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1062
- throw cast_error (" Unable to cast Python instance to C++ type (#define "
1062
+ throw cast_error (" Unable to cast Python instance of type "
1063
+ + (std::string) str (type::handle_of (handle)) + " to C++ type '?' (#define "
1063
1064
" PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)" );
1064
1065
#else
1065
1066
throw cast_error (" Unable to cast Python instance of type "
@@ -1127,7 +1128,8 @@ detail::enable_if_t<!detail::move_never<T>::value, T> move(object &&obj) {
1127
1128
if (obj.ref_count () > 1 ) {
1128
1129
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1129
1130
throw cast_error (
1130
- " Unable to cast Python instance to C++ rvalue: instance has multiple references"
1131
+ " Unable to cast Python " + (std::string) str (type::handle_of (obj))
1132
+ + " instance to C++ rvalue: instance has multiple references"
1131
1133
" (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)" );
1132
1134
#else
1133
1135
throw cast_error (" Unable to move from Python " + (std::string) str (type::handle_of (obj))
@@ -1237,8 +1239,8 @@ PYBIND11_NAMESPACE_END(detail)
1237
1239
// The overloads could coexist, i.e. the #if is not strictly speaking needed,
1238
1240
// but it is an easy minor optimization.
1239
1241
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1240
- inline cast_error cast_error_unable_to_convert_call_arg () {
1241
- return cast_error (" Unable to convert call argument to Python object (#define "
1242
+ inline cast_error cast_error_unable_to_convert_call_arg (const std::string &name ) {
1243
+ return cast_error (" Unable to convert call argument ' " + name + " ' to Python object (#define "
1242
1244
" PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)" );
1243
1245
}
1244
1246
#else
@@ -1262,7 +1264,7 @@ tuple make_tuple(Args &&...args_) {
1262
1264
for (size_t i = 0 ; i < args.size (); i++) {
1263
1265
if (!args[i]) {
1264
1266
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1265
- throw cast_error_unable_to_convert_call_arg ();
1267
+ throw cast_error_unable_to_convert_call_arg (std::to_string (i) );
1266
1268
#else
1267
1269
std::array<std::string, size> argtypes{{type_id<Args>()...}};
1268
1270
throw cast_error_unable_to_convert_call_arg (std::to_string (i), argtypes[i]);
@@ -1552,7 +1554,7 @@ class unpacking_collector {
1552
1554
detail::make_caster<T>::cast (std::forward<T>(x), policy, {}));
1553
1555
if (!o) {
1554
1556
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1555
- throw cast_error_unable_to_convert_call_arg ();
1557
+ throw cast_error_unable_to_convert_call_arg (std::to_string (args_list. size ()) );
1556
1558
#else
1557
1559
throw cast_error_unable_to_convert_call_arg (std::to_string (args_list.size ()),
1558
1560
type_id<T>());
@@ -1584,7 +1586,7 @@ class unpacking_collector {
1584
1586
}
1585
1587
if (!a.value ) {
1586
1588
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1587
- throw cast_error_unable_to_convert_call_arg ();
1589
+ throw cast_error_unable_to_convert_call_arg (a. name );
1588
1590
#else
1589
1591
throw cast_error_unable_to_convert_call_arg (a.name , a.type );
1590
1592
#endif
0 commit comments