Skip to content

Commit 0c8edf0

Browse files
committed
Include limit in error message
1 parent f368ccc commit 0c8edf0

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Tests/test_file_webp.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ def test_write_encoding_error_bad_dimension(self, tmp_path: Path) -> None:
163163
im = Image.new("L", (16384, 16384))
164164
with pytest.raises(ValueError) as e:
165165
im.save(temp_file)
166-
assert str(e.value) == "encoding error 5: Image size exceeds WebP limit"
166+
assert (
167+
str(e.value) == "encoding error 5: Image size exceeds WebP limit of 16383"
168+
)
167169

168170
def test_WebPEncode_with_invalid_args(self) -> None:
169171
"""

src/_webp.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,9 +673,11 @@ WebPEncode_wrapper(PyObject *self, PyObject *args) {
673673
WebPPictureFree(&pic);
674674
if (!ok) {
675675
int error_code = (&pic)->error_code;
676-
const char *message = "";
676+
static char message[50] = "";
677677
if (error_code == VP8_ENC_ERROR_BAD_DIMENSION) {
678-
message = ": Image size exceeds WebP limit";
678+
sprintf(
679+
message, ": Image size exceeds WebP limit of %d", WEBP_MAX_DIMENSION
680+
);
679681
}
680682
PyErr_Format(PyExc_ValueError, "encoding error %d%s", error_code, message);
681683
return NULL;

0 commit comments

Comments
 (0)