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