Skip to content

Commit 572259b

Browse files
authored
Merge pull request #4885 from radarhere/exception
2 parents b9081d2 + 0af193a commit 572259b

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Tests/test_imagefile.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,8 @@ def test_no_format(self):
244244
im = MockImageFile(buf)
245245
assert im.format is None
246246
assert im.get_format_mimetype() is None
247+
248+
def test_oserror(self):
249+
im = Image.new("RGB", (1, 1))
250+
with pytest.raises(OSError):
251+
im.save(BytesIO(), "JPEG2000")

src/PIL/ImageFile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ def _save(im, fp, tile, bufsize=0):
509509
try:
510510
fh = fp.fileno()
511511
fp.flush()
512-
except (AttributeError, io.UnsupportedOperation) as e:
512+
except (AttributeError, io.UnsupportedOperation) as exc:
513513
# compress to Python file-compatible object
514514
for e, b, o, a in tile:
515515
e = Image._getencoder(im.mode, e, a, im.encoderconfig)
@@ -526,7 +526,7 @@ def _save(im, fp, tile, bufsize=0):
526526
if s:
527527
break
528528
if s < 0:
529-
raise OSError("encoder error %d when writing image file" % s) from e
529+
raise OSError("encoder error %d when writing image file" % s) from exc
530530
e.cleanup()
531531
else:
532532
# slight speedup: compress to real file object

0 commit comments

Comments
 (0)