Skip to content

Commit

Permalink
Include limit in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Aug 22, 2024
1 parent f368ccc commit 0c8edf0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Tests/test_file_webp.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ def test_write_encoding_error_bad_dimension(self, tmp_path: Path) -> None:
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:
"""
Expand Down
6 changes: 4 additions & 2 deletions src/_webp.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,9 +673,11 @@ WebPEncode_wrapper(PyObject *self, PyObject *args) {
WebPPictureFree(&pic);
if (!ok) {
int error_code = (&pic)->error_code;
const char *message = "";
static 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;
Expand Down

0 comments on commit 0c8edf0

Please sign in to comment.