Make marshalling errors a little more informative as to what went wrong

This commit is contained in:
Nick Coghlan 2009-03-15 03:24:46 +00:00
parent 2ace4cf813
commit 8eba5ed0d9
1 changed files with 13 additions and 13 deletions

View File

@ -576,7 +576,7 @@ r_object(RFILE *p)
n = r_long(p); n = r_long(p);
if (n < -INT_MAX || n > INT_MAX) { if (n < -INT_MAX || n > INT_MAX) {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"bad marshal data"); "bad marshal data (long size out of range)");
retval = NULL; retval = NULL;
break; break;
} }
@ -592,7 +592,7 @@ r_object(RFILE *p)
if (digit < 0) { if (digit < 0) {
Py_DECREF(ob); Py_DECREF(ob);
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"bad marshal data"); "bad marshal data (negative digit in long)");
ob = NULL; ob = NULL;
break; break;
} }
@ -709,7 +709,7 @@ r_object(RFILE *p)
case TYPE_STRING: case TYPE_STRING:
n = r_long(p); n = r_long(p);
if (n < 0 || n > INT_MAX) { if (n < 0 || n > INT_MAX) {
PyErr_SetString(PyExc_ValueError, "bad marshal data"); PyErr_SetString(PyExc_ValueError, "bad marshal data (string size out of range)");
retval = NULL; retval = NULL;
break; break;
} }
@ -738,7 +738,7 @@ r_object(RFILE *p)
case TYPE_STRINGREF: case TYPE_STRINGREF:
n = r_long(p); n = r_long(p);
if (n < 0 || n >= PyList_GET_SIZE(p->strings)) { if (n < 0 || n >= PyList_GET_SIZE(p->strings)) {
PyErr_SetString(PyExc_ValueError, "bad marshal data"); PyErr_SetString(PyExc_ValueError, "bad marshal data (string ref out of range)");
retval = NULL; retval = NULL;
break; break;
} }
@ -754,7 +754,7 @@ r_object(RFILE *p)
n = r_long(p); n = r_long(p);
if (n < 0 || n > INT_MAX) { if (n < 0 || n > INT_MAX) {
PyErr_SetString(PyExc_ValueError, "bad marshal data"); PyErr_SetString(PyExc_ValueError, "bad marshal data (unicode size out of range)");
retval = NULL; retval = NULL;
break; break;
} }
@ -780,7 +780,7 @@ r_object(RFILE *p)
case TYPE_TUPLE: case TYPE_TUPLE:
n = r_long(p); n = r_long(p);
if (n < 0 || n > INT_MAX) { if (n < 0 || n > INT_MAX) {
PyErr_SetString(PyExc_ValueError, "bad marshal data"); PyErr_SetString(PyExc_ValueError, "bad marshal data (tuple size out of range)");
retval = NULL; retval = NULL;
break; break;
} }
@ -794,7 +794,7 @@ r_object(RFILE *p)
if ( v2 == NULL ) { if ( v2 == NULL ) {
if (!PyErr_Occurred()) if (!PyErr_Occurred())
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"NULL object in marshal data"); "NULL object in marshal data for tuple");
Py_DECREF(v); Py_DECREF(v);
v = NULL; v = NULL;
break; break;
@ -807,7 +807,7 @@ r_object(RFILE *p)
case TYPE_LIST: case TYPE_LIST:
n = r_long(p); n = r_long(p);
if (n < 0 || n > INT_MAX) { if (n < 0 || n > INT_MAX) {
PyErr_SetString(PyExc_ValueError, "bad marshal data"); PyErr_SetString(PyExc_ValueError, "bad marshal data (list size out of range)");
retval = NULL; retval = NULL;
break; break;
} }
@ -821,7 +821,7 @@ r_object(RFILE *p)
if ( v2 == NULL ) { if ( v2 == NULL ) {
if (!PyErr_Occurred()) if (!PyErr_Occurred())
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"NULL object in marshal data"); "NULL object in marshal data for list");
Py_DECREF(v); Py_DECREF(v);
v = NULL; v = NULL;
break; break;
@ -859,7 +859,7 @@ r_object(RFILE *p)
case TYPE_FROZENSET: case TYPE_FROZENSET:
n = r_long(p); n = r_long(p);
if (n < 0 || n > INT_MAX) { if (n < 0 || n > INT_MAX) {
PyErr_SetString(PyExc_ValueError, "bad marshal data"); PyErr_SetString(PyExc_ValueError, "bad marshal data (set size out of range)");
retval = NULL; retval = NULL;
break; break;
} }
@ -873,7 +873,7 @@ r_object(RFILE *p)
if ( v2 == NULL ) { if ( v2 == NULL ) {
if (!PyErr_Occurred()) if (!PyErr_Occurred())
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"NULL object in marshal data"); "NULL object in marshal data for set");
Py_DECREF(v); Py_DECREF(v);
v = NULL; v = NULL;
break; break;
@ -973,7 +973,7 @@ r_object(RFILE *p)
default: default:
/* Bogus data got written, which isn't ideal. /* Bogus data got written, which isn't ideal.
This will let you keep working and recover. */ This will let you keep working and recover. */
PyErr_SetString(PyExc_ValueError, "bad marshal data"); PyErr_SetString(PyExc_ValueError, "bad marshal data (unknown type code)");
retval = NULL; retval = NULL;
break; break;
@ -992,7 +992,7 @@ read_object(RFILE *p)
} }
v = r_object(p); v = r_object(p);
if (v == NULL && !PyErr_Occurred()) if (v == NULL && !PyErr_Occurred())
PyErr_SetString(PyExc_TypeError, "NULL object in marshal data"); PyErr_SetString(PyExc_TypeError, "NULL object in marshal data for object");
return v; return v;
} }