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

@ -442,28 +442,48 @@ pack_args(DCPacker &packer, PyObject *sequence) const {
if (!Notify::ptr()->has_assert_failed()) {
ostringstream strm;
PyObject *tuple = PySequence_Tuple(sequence);
if (tuple == (PyObject *)NULL) {
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);
strm << "Arguments to field " << get_name()
<< " not a sequence: " << PyString_AsString(str);
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 {
PyObject *str = PyObject_Str(tuple);
// 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);
if (packer.had_pack_error()) {
strm << "Incorrect arguments to field: " << get_name()
strm << "Value for " << get_name() << " not a sequence: " \
<< PyString_AsString(str);
Py_DECREF(str);
} else {
strm << "Value out of range on field: " << get_name()
<< PyString_AsString(str);
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);
}
Py_DECREF(str);
Py_DECREF(tuple);
}
nassert_raise(strm.str());

View File

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