This commit is contained in:
Francesco Biscani 2024-09-20 23:42:30 -07:00 committed by GitHub
commit 589ed702a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 2 deletions

View File

@ -1078,9 +1078,13 @@ protected:
msg += '\n'; msg += '\n';
} }
msg += "\nInvoked with: "; msg += "\nInvoked with: ";
constexpr auto max_args_repr_size = 5000u;
const auto orig_msg_size = msg.size();
auto args_ = reinterpret_borrow<tuple>(args_in); auto args_ = reinterpret_borrow<tuple>(args_in);
bool some_args = false; bool some_args = false;
for (size_t ti = overloads->is_constructor ? 1 : 0; ti < args_.size(); ++ti) { for (size_t ti = overloads->is_constructor ? 1 : 0;
ti < args_.size() && msg.size() - orig_msg_size <= max_args_repr_size;
++ti) {
if (!some_args) { if (!some_args) {
some_args = true; some_args = true;
} else { } else {
@ -1092,7 +1096,7 @@ protected:
msg += "<repr raised Error>"; msg += "<repr raised Error>";
} }
} }
if (kwargs_in) { if (kwargs_in && msg.size() - orig_msg_size <= max_args_repr_size) {
auto kwargs = reinterpret_borrow<dict>(kwargs_in); auto kwargs = reinterpret_borrow<dict>(kwargs_in);
if (!kwargs.empty()) { if (!kwargs.empty()) {
if (some_args) { if (some_args) {
@ -1101,6 +1105,10 @@ protected:
msg += "kwargs: "; msg += "kwargs: ";
bool first = true; bool first = true;
for (const auto &kwarg : kwargs) { for (const auto &kwarg : kwargs) {
if (msg.size() - orig_msg_size > max_args_repr_size) {
break;
}
if (first) { if (first) {
first = false; first = false;
} else { } else {
@ -1116,6 +1124,10 @@ protected:
} }
} }
if (msg.size() - orig_msg_size > max_args_repr_size) {
msg += "...";
}
append_note_if_missing_header_is_suspected(msg); append_note_if_missing_header_is_suspected(msg);
// Attach additional error info to the exception if supported // Attach additional error info to the exception if supported
if (PyErr_Occurred()) { if (PyErr_Occurred()) {