Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include code in WebP error #5471

Merged
merged 1 commit into from May 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions Tests/test_file_webp.py
@@ -1,5 +1,6 @@
import io
import re
import sys

import pytest

Expand Down Expand Up @@ -119,6 +120,14 @@ def test_write_unsupported_mode_P(self, tmp_path):

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

@pytest.mark.skipif(sys.maxsize <= 2 ** 32, reason="Requires 64-bit system")
def test_write_encoding_error_message(self, tmp_path):
temp_file = str(tmp_path / "temp.webp")
im = Image.new("RGB", (15000, 15000))
with pytest.raises(ValueError) as e:
im.save(temp_file, method=0)
assert str(e.value) == "encoding error 6"

def test_WebPEncode_with_invalid_args(self):
"""
Calling encoder functions with no arguments should result in an error.
Expand Down
2 changes: 1 addition & 1 deletion src/_webp.c
Expand Up @@ -663,7 +663,7 @@ WebPEncode_wrapper(PyObject *self, PyObject *args) {

WebPPictureFree(&pic);
if (!ok) {
PyErr_SetString(PyExc_ValueError, "encoding error");
PyErr_Format(PyExc_ValueError, "encoding error %d", (&pic)->error_code);
return NULL;
}
output = writer.mem;
Expand Down