File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -1122,9 +1122,13 @@ class cpp_function : public function {
1122
1122
msg += ' \n ' ;
1123
1123
}
1124
1124
msg += " \n Invoked with: " ;
1125
+ constexpr auto max_args_repr_size = 5000u ;
1126
+ const auto orig_msg_size = msg.size ();
1125
1127
auto args_ = reinterpret_borrow<tuple>(args_in);
1126
1128
bool some_args = false ;
1127
- for (size_t ti = overloads->is_constructor ? 1 : 0 ; ti < args_.size (); ++ti) {
1129
+ for (size_t ti = overloads->is_constructor ? 1 : 0 ;
1130
+ ti < args_.size () && msg.size () - orig_msg_size <= max_args_repr_size;
1131
+ ++ti) {
1128
1132
if (!some_args) {
1129
1133
some_args = true ;
1130
1134
} else {
@@ -1136,7 +1140,7 @@ class cpp_function : public function {
1136
1140
msg += " <repr raised Error>" ;
1137
1141
}
1138
1142
}
1139
- if (kwargs_in) {
1143
+ if (kwargs_in && msg. size () - orig_msg_size <= max_args_repr_size ) {
1140
1144
auto kwargs = reinterpret_borrow<dict>(kwargs_in);
1141
1145
if (!kwargs.empty ()) {
1142
1146
if (some_args) {
@@ -1145,6 +1149,10 @@ class cpp_function : public function {
1145
1149
msg += " kwargs: " ;
1146
1150
bool first = true ;
1147
1151
for (const auto &kwarg : kwargs) {
1152
+ if (msg.size () - orig_msg_size > max_args_repr_size) {
1153
+ break ;
1154
+ }
1155
+
1148
1156
if (first) {
1149
1157
first = false ;
1150
1158
} else {
@@ -1160,6 +1168,10 @@ class cpp_function : public function {
1160
1168
}
1161
1169
}
1162
1170
1171
+ if (msg.size () - orig_msg_size > max_args_repr_size) {
1172
+ msg += " ..." ;
1173
+ }
1174
+
1163
1175
append_note_if_missing_header_is_suspected (msg);
1164
1176
// Attach additional error info to the exception if supported
1165
1177
if (PyErr_Occurred ()) {
You can’t perform that action at this time.
0 commit comments