Skip to content

Commit 4cd0e1b

Browse files
committed
Include code in WebP error
1 parent 8354fa4 commit 4cd0e1b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Tests/test_file_webp.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ def test_write_unsupported_mode_P(self, tmp_path):
119119

120120
self._roundtrip(tmp_path, "P", 50.0)
121121

122+
def test_write_encoding_error_message(self, tmp_path):
123+
temp_file = str(tmp_path / "temp.webp")
124+
im = Image.new("RGB", (15000, 15000))
125+
with pytest.raises(ValueError) as e:
126+
im.save(temp_file, method=0)
127+
assert str(e.value) == "encoding error 6"
128+
122129
def test_WebPEncode_with_invalid_args(self):
123130
"""
124131
Calling encoder functions with no arguments should result in an error.

src/_webp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ WebPEncode_wrapper(PyObject *self, PyObject *args) {
663663

664664
WebPPictureFree(&pic);
665665
if (!ok) {
666-
PyErr_SetString(PyExc_ValueError, "encoding error");
666+
PyErr_Format(PyExc_ValueError, "encoding error %d", pic.error_code);
667667
return NULL;
668668
}
669669
output = writer.mem;

0 commit comments

Comments
 (0)