Include limit in error message

This commit is contained in:
Andrew Murray 2024-08-22 17:50:42 +10:00
parent f368ccc06e
commit d49ea37811
2 changed files with 7 additions and 3 deletions

View File

@ -163,7 +163,9 @@ class TestFileWebp:
im = Image.new("L", (16384, 16384))
with pytest.raises(ValueError) as e:
im.save(temp_file)
assert str(e.value) == "encoding error 5: Image size exceeds WebP limit"
assert (
str(e.value) == "encoding error 5: Image size exceeds WebP limit of 16383"
)
def test_WebPEncode_with_invalid_args(self) -> None:
"""

View File

@ -673,9 +673,11 @@ WebPEncode_wrapper(PyObject *self, PyObject *args) {
WebPPictureFree(&pic);
if (!ok) {
int error_code = (&pic)->error_code;
const char *message = "";
char message[50] = "";
if (error_code == VP8_ENC_ERROR_BAD_DIMENSION) {
message = ": Image size exceeds WebP limit";
sprintf(
message, ": Image size exceeds WebP limit of %d", WEBP_MAX_DIMENSION
);
}
PyErr_Format(PyExc_ValueError, "encoding error %d%s", error_code, message);
return NULL;