protobuf: Improve error message while constructing messages in Python.
"Value is not iterable" is sometimes not that helpful. Lets at least mention the field name.
PiperOrigin-RevId: 489485451
diff --git a/python/google/protobuf/pyext/message.cc b/python/google/protobuf/pyext/message.cc
index f4dd00d..108dd52 100644
--- a/python/google/protobuf/pyext/message.cc
+++ b/python/google/protobuf/pyext/message.cc
@@ -1100,7 +1100,8 @@
reinterpret_cast<RepeatedCompositeContainer*>(container.get());
ScopedPyObjectPtr iter(PyObject_GetIter(value));
if (iter == nullptr) {
- PyErr_SetString(PyExc_TypeError, "Value must be iterable");
+ PyErr_Format(PyExc_TypeError, "Value of field '%s' must be iterable",
+ descriptor->name().c_str());
return -1;
}
ScopedPyObjectPtr next;
@@ -1129,7 +1130,8 @@
reinterpret_cast<RepeatedScalarContainer*>(container.get());
ScopedPyObjectPtr iter(PyObject_GetIter(value));
if (iter == nullptr) {
- PyErr_SetString(PyExc_TypeError, "Value must be iterable");
+ PyErr_Format(PyExc_TypeError, "Value of field '%s' must be iterable",
+ descriptor->name().c_str());
return -1;
}
ScopedPyObjectPtr next;