[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
This commit is contained in:
Xavier Morel
2012-11-04 20:25:08 +01:00
parent e242bc990b
commit b6ce978020
+6 -4
View File
@@ -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 '<script>window.top.%s(%s);</script>' % (