summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-09-16 16:41:57 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-09-16 16:41:57 (GMT)
commitcfc31926774f876323e64cb13a26de0d7061be4c (patch)
tree5cebbafb0e8ddd4b43047a44830e3c66c6ff5c13 /Python
parent6543b45b0c0adfd8a91ad64997ffe507e9482b0c (diff)
downloadcpython-cfc31926774f876323e64cb13a26de0d7061be4c.zip
cpython-cfc31926774f876323e64cb13a26de0d7061be4c.tar.gz
cpython-cfc31926774f876323e64cb13a26de0d7061be4c.tar.bz2
SF bug #1014215: Unspecific errors with metaclass
High level error message was stomping useful detailed messages from lower level routines. The new approach is to augment string error messages returned by the low level routines. The provides both high and low level information. If the exception value is not a string, no changes are made. To see the improved messages in action, type: import random class R(random): pass class B(bool): pass
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 186bc82..2223aba 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4086,10 +4086,22 @@ build_class(PyObject *methods, PyObject *bases, PyObject *name)
/* A type error here likely means that the user passed
in a base that was not a class (such the random module
instead of the random.random type). Help them out with
- a more informative error message */
- PyErr_SetString(PyExc_TypeError,
- "Error when calling the metaclass.\n" \
- "Make sure the base arguments are valid.");
+ by augmenting the error message with more information.*/
+
+ PyObject *ptype, *pvalue, *ptraceback;
+
+ PyErr_Fetch(&ptype, &pvalue, &ptraceback);
+ if (PyString_Check(pvalue)) {
+ PyObject *newmsg;
+ newmsg = PyString_FromFormat(
+ "Error when calling the metaclass bases\n %s",
+ PyString_AS_STRING(pvalue));
+ if (newmsg != NULL) {
+ Py_DECREF(pvalue);
+ pvalue = newmsg;
+ }
+ }
+ PyErr_Restore(ptype, pvalue, ptraceback);
}
return result;
}