clarify error messages, especially with switch

This commit is contained in:
David Rose 2005-05-23 23:54:12 +00:00
parent a1e77c450b
commit bc65ead4fb
2 changed files with 34 additions and 14 deletions

View File

@ -443,12 +443,31 @@ pack_args(DCPacker &packer, PyObject *sequence) const {
if (!Notify::ptr()->has_assert_failed()) { if (!Notify::ptr()->has_assert_failed()) {
ostringstream strm; ostringstream strm;
if (as_parameter() != (DCParameter *)NULL) {
// If it's a parameter-type field, the value may or may not be a
// sequence.
PyObject *str = PyObject_Str(sequence);
nassertr(str != (PyObject *)NULL, false);
if (packer.had_pack_error()) {
strm << "Incorrect arguments to field: " << get_name()
<< " = " << PyString_AsString(str);
} else {
strm << "Value out of range on field: " << get_name()
<< " = " << PyString_AsString(str);
}
Py_DECREF(str);
} else {
// If it's a molecular or atomic field, the value should be a
// sequence.
PyObject *tuple = PySequence_Tuple(sequence); PyObject *tuple = PySequence_Tuple(sequence);
if (tuple == (PyObject *)NULL) { if (tuple == (PyObject *)NULL) {
PyObject *str = PyObject_Str(sequence); PyObject *str = PyObject_Str(sequence);
nassertr(str != (PyObject *)NULL, false); nassertr(str != (PyObject *)NULL, false);
strm << "Arguments to field " << get_name()
<< " not a sequence: " << PyString_AsString(str); strm << "Value for " << get_name() << " not a sequence: " \
<< PyString_AsString(str);
Py_DECREF(str); Py_DECREF(str);
} else { } else {
@ -465,6 +484,7 @@ pack_args(DCPacker &packer, PyObject *sequence) const {
Py_DECREF(str); Py_DECREF(str);
Py_DECREF(tuple); Py_DECREF(tuple);
} }
}
nassert_raise(strm.str()); nassert_raise(strm.str());
} }

View File

@ -1096,7 +1096,7 @@ handle_switch(const DCSwitchParameter *switch_parameter) {
if (new_parent == (DCPackerInterface *)NULL) { if (new_parent == (DCPackerInterface *)NULL) {
// This means an invalid value was packed for the key. // This means an invalid value was packed for the key.
_pack_error = true; _range_error = true;
return; return;
} }