From 4080f160b6656db180cbb8030f706e6ac9d92988 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 7 May 2021 00:12:03 +1000 Subject: [PATCH] Include code in WebP error --- Tests/test_file_webp.py | 9 +++++++++ src/_webp.c | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Tests/test_file_webp.py b/Tests/test_file_webp.py index cde7020ed..7fdb32ef4 100644 --- a/Tests/test_file_webp.py +++ b/Tests/test_file_webp.py @@ -1,5 +1,6 @@ import io import re +import sys import pytest @@ -119,6 +120,14 @@ class TestFileWebp: 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. diff --git a/src/_webp.c b/src/_webp.c index 4d51d99df..6c357dbb0 100644 --- a/src/_webp.c +++ b/src/_webp.c @@ -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;