diff MoinMoin/action/AttachFile.py @ 6119:c506e1897d93

catch IOError for zipfile errors zipfile.iszipfile() has false positives that trigger exceptions when trying to process such a file as zipfile (although it is not). improve error messages: mention pagename and filename
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 28 Oct 2016 17:03:20 +0200
parents 4716268c34e3
children eceb70c41ecc
line wrap: on
line diff
--- a/MoinMoin/action/AttachFile.py	Tue Sep 20 20:54:17 2016 +0200
+++ b/MoinMoin/action/AttachFile.py	Fri Oct 28 17:03:20 2016 +0200
@@ -494,7 +494,7 @@
                         links.append(fmt.url(1, getAttachUrl(pagename, file, request, do='unzip')) +
                                      fmt.text(label_unzip) +
                                      fmt.url(0))
-            except (RuntimeError, zipfile.BadZipfile, zipfile.LargeZipFile):
+            except (IOError, RuntimeError, zipfile.BadZipfile, zipfile.LargeZipFile):
                 # We don't want to crash with a traceback here (an exception
                 # here could be caused by an uploaded defective zip file - and
                 # if we crash here, the user does not get a UI to remove the
@@ -504,7 +504,8 @@
                 # archive).
                 # BadZipfile/LargeZipFile are raised when there are some
                 # specific problems with the archive file.
-                logging.exception("An exception within zip file attachment handling occurred:")
+                logging.exception("An exception within zip file attachment [%r:%r] handling occurred:" % (
+                     pagename, file))
 
             html.append(fmt.listitem(1))
             html.append("[%s]" % "&nbsp;| ".join(links))
@@ -1178,7 +1179,7 @@
                         'filelist': ', '.join(not_overwritten), }
             else:
                 msg = _("Attachment '%(filename)s' unzipped.") % {'filename': filename}
-    except (RuntimeError, zipfile.BadZipfile, zipfile.LargeZipFile), err:
+    except (IOError, RuntimeError, zipfile.BadZipfile, zipfile.LargeZipFile), err:
         # We don't want to crash with a traceback here (an exception
         # here could be caused by an uploaded defective zip file - and
         # if we crash here, the user does not get a UI to remove the
@@ -1188,7 +1189,8 @@
         # archive).
         # BadZipfile/LargeZipFile are raised when there are some
         # specific problems with the archive file.
-        logging.exception("An exception within zip file attachment handling occurred:")
+        logging.exception("An exception within zip file attachment [%r:%r] handling occurred:" % (
+            pagename, filename))
         msg = _("A severe error occurred:") + ' ' + str(err)
 
     upload_form(pagename, request, msg=msg)
@@ -1259,7 +1261,7 @@
                 request.write(wikiutil.escape("%-46s %s %12d\n" % (zinfo.filename, date, zinfo.file_size)))
             request.write("</pre>")
             return
-    except (RuntimeError, zipfile.BadZipfile, zipfile.LargeZipFile):
+    except (IOError, RuntimeError, zipfile.BadZipfile, zipfile.LargeZipFile):
         # We don't want to crash with a traceback here (an exception
         # here could be caused by an uploaded defective zip file - and
         # if we crash here, the user does not get a UI to remove the
@@ -1269,7 +1271,8 @@
         # archive).
         # BadZipfile/LargeZipFile are raised when there are some
         # specific problems with the archive file.
-        logging.exception("An exception within zip file attachment handling occurred:")
+        logging.exception("An exception within zip file attachment [%r:%r] handling occurred:" % (
+            pagename, filename))
         return
 
     from MoinMoin import macro