Mercurial > cpython-lru_cache-weakref
diff Modules/zlibmodule.c @ 61522:2a70c80349b0 2.6
Merged revisions 81098 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81098 | antoine.pitrou | 2010-05-12 01:42:28 +0200 (mer., 12 mai 2010) | 5 lines
Issue #8681: Make the zlib module's error messages more informative when
the zlib itself doesn't give any detailed explanation.
........
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Tue, 11 May 2010 23:45:55 +0000 |
| parents | e38335d4df91 |
| children | 787b969d37f0 |
line wrap: on
line diff
--- a/Modules/zlibmodule.c Tue May 11 23:33:53 2010 +0000 +++ b/Modules/zlibmodule.c Tue May 11 23:45:55 2010 +0000 @@ -72,10 +72,24 @@ static void zlib_error(z_stream zst, int err, char *msg) { - if (zst.msg == Z_NULL) + const char *zmsg = zst.msg; + if (zmsg == Z_NULL) { + switch (err) { + case Z_BUF_ERROR: + zmsg = "incomplete or truncated stream"; + break; + case Z_STREAM_ERROR: + zmsg = "inconsistent stream state"; + break; + case Z_DATA_ERROR: + zmsg = "invalid input data"; + break; + } + } + if (zmsg == Z_NULL) PyErr_Format(ZlibError, "Error %d %s", err, msg); else - PyErr_Format(ZlibError, "Error %d %s: %.200s", err, msg, zst.msg); + PyErr_Format(ZlibError, "Error %d %s: %.200s", err, msg, zmsg); } PyDoc_STRVAR(compressobj__doc__, @@ -248,8 +262,7 @@ * process the inflate call() due to an error in the data. */ if (zst.avail_out > 0) { - PyErr_Format(ZlibError, "Error %i while decompressing data", - err); + zlib_error(zst, err, "while decompressing data"); inflateEnd(&zst); goto error; }
