summaryrefslogtreecommitdiff
path: root/odoo/tools/image.py
diff options
context:
space:
mode:
authorRomainLibert <rli@odoo.com>2019-09-18 09:17:17 +0000
committerRomainLibert <rli@odoo.com>2019-09-18 10:14:12 +0000
commit85eeaccf065b151dbc9f0e1a24f1b4f674dec6cc (patch)
tree797bc7049d38e5e0c5af0bbd422c7f7a78d0d300 /odoo/tools/image.py
parentf60acb4f49132a2103db8e868e830b4e5e11b8fb (diff)
[FIX] tools: use user friendly message in case of error
closes odoo/odoo#37058 Signed-off-by: Nans Lefebvre (len) <len@odoo.com>
Diffstat (limited to 'odoo/tools/image.py')
-rw-r--r--odoo/tools/image.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/odoo/tools/image.py b/odoo/tools/image.py
index 999b5c1e5e7..f5b4b953da9 100644
--- a/odoo/tools/image.py
+++ b/odoo/tools/image.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import base64
+import binascii
import io
from PIL import Image
@@ -9,6 +10,7 @@ from PIL import IcoImagePlugin
from random import randrange
+from odoo.exceptions import UserError
from odoo.tools.translate import _
@@ -49,8 +51,7 @@ class ImageProcess():
:rtype: ImageProcess
:raise: ValueError if `verify_resolution` is True and the image is too large
- :raise: binascii.Error: if the base64 is incorrect
- :raise: OSError if the image can't be identified by PIL
+ :raise: UserError if the base64 is incorrect or the image can't be identified by PIL
"""
self.base64_source = base64_source or False
self.operationsCount = 0
@@ -339,10 +340,12 @@ def base64_to_image(base64_source):
:return: the PIL image
:rtype: PIL.Image
- :raise: binascii.Error: if the base64 is incorrect
- :raise: OSError if the image can't be identified by PIL
+ :raise: UserError if the base64 is incorrect or the image can't be identified by PIL
"""
- return Image.open(io.BytesIO(base64.b64decode(base64_source)))
+ try:
+ return Image.open(io.BytesIO(base64.b64decode(base64_source)))
+ except (OSError, binascii.Error):
+ raise UserError(_("This file could not be decoded as an image file. Please try with a different file."))
def image_to_base64(image, format, **params):