From b6ce97802036ea6ca008bc46c1fd6bfaaea16ac5 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Sun, 4 Nov 2012 20:25:08 +0100 Subject: [PATCH] [FIX] avoid overwriting sensible error message with garbage when reading or decoding the CSV file fails also improve error message in case of decoding error (turns out UnicodeDecodeError has everything you need to know exactly what blew up, who knew?) bzr revid: xmo@openerp.com-20121104192508-62gnf3syv59am4ki --- addons/web/controllers/main.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 57a47c9c509..79a7916607f 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1953,13 +1953,15 @@ class Import(View): # filtering in case of e.g. o2m content rows) if any(row) ] - except UnicodeDecodeError: - error = u"Failed to decode CSV file using encoding %s" % csvcode + except UnicodeDecodeError, e: + # decode with iso-8859-1 for error display: always works-ish + error = u"Failed to decode cell %r using encoding %s: '%s'" % ( + e.object, e.encoding, e.reason) except csv.Error, e: error = u"Could not process CSV file: %s" % e - # If the file contains nothing, - if not data: + # If the file contains nothing, and the import has not already blown up + if not (error or data): error = u"File to import is empty" if error: return '' % (