Bartosz Dziewoński has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/309909

Change subject: Further improve handling of silly canvas #drawImage exceptions
......................................................................

Further improve handling of silly canvas #drawImage exceptions

* Do not re-throw in uw.EventFlowLogger#maybeLogFirefoxCanvasException.
  I've looked a bit more at the exceptions we have logged, and
  without exception (heheh) they're useless and just mean that
  thumbnailing failed for a reason clearly beyond our control.
* Report failure in mw.UploadWizardUpload#getTransformedCanvasElement
  by returning null.
* In mw.UploadWizardUpload#getScaledImageElement, fall back
  to #getBrowserScaledImageElement if #getTransformedCanvasElement
  fails.
* Add some comments quoting some of the stupid exceptions
  that we've seen in the logs, to justify the try...catch.

Follow-up to 5f5fdae13b30a39fd9b198e97d29df45a70e9ad2,
c6b74d5e68470c102e07237d127d54bdb9302ab7.

Bug: T136831
Bug: T145341
Change-Id: Ie60421358d2178c0d8189018720021d1b3d58dbb
---
M resources/mw.UploadWizardUpload.js
M resources/uw.EventFlowLogger.js
2 files changed, 20 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard 
refs/changes/09/309909/1

diff --git a/resources/mw.UploadWizardUpload.js 
b/resources/mw.UploadWizardUpload.js
index 5859345..43ff173 100644
--- a/resources/mw.UploadWizardUpload.js
+++ b/resources/mw.UploadWizardUpload.js
@@ -937,7 +937,7 @@
         *
         * @param {HTMLImageElement} image
         * @param {Object} constraints Width & height constraints
-        * @return {HTMLCanvasElement}
+        * @return {HTMLCanvasElement|null}
         */
        mw.UploadWizardUpload.prototype.getTransformedCanvasElement = function 
( image, constraints ) {
                var angle, scaleConstraints, scaling, width, height,
@@ -1001,9 +1001,17 @@
                ctx.clearRect( 0, 0, width, height );
                ctx.rotate( rotation / 180 * Math.PI );
                try {
+                       // Calling #drawImage likes to throw all kinds of 
ridiculous exceptions in various browsers,
+                       // including but not limited to:
+                       // * (Firefox) NS_ERROR_NOT_AVAILABLE:
+                       // * (Internet Explorer / Edge) Not enough storage is 
available to complete this operation.
+                       // * (Internet Explorer / Edge) Unspecified error.
+                       // * (Safari) IndexSizeError: Index or size was 
negative, or greater than the allowed value.
+                       // There is nothing we can do about this. It's okay 
though, there just won't be a thumbnail.
                        ctx.drawImage( image, x, y, width, height );
                } catch ( err ) {
                        uw.eventFlowLogger.maybeLogFirefoxCanvasException( err, 
image );
+                       return null;
                }
 
                return $canvas;
@@ -1038,7 +1046,7 @@
         * @return {HTMLCanvasElement|HTMLImageElement}
         */
        mw.UploadWizardUpload.prototype.getScaledImageElement = function ( 
image, width, height ) {
-               var constraints;
+               var constraints, transform;
                if ( width === undefined || width === null || width <= 0 ) {
                        width = mw.UploadWizard.config.thumbnailWidth;
                }
@@ -1047,9 +1055,14 @@
                        height: ( height === undefined ? null : parseInt( 
height, 10 ) )
                };
 
-               return mw.canvas.isAvailable() ?
-                       this.getTransformedCanvasElement( image, constraints ) :
-                       this.getBrowserScaledImageElement( image, constraints );
+               if ( mw.canvas.isAvailable() ) {
+                       transform = this.getTransformedCanvasElement( image, 
constraints );
+                       if ( transform ) {
+                               return transform;
+                       }
+               }
+               // No canvas support or canvas drawing failed mysteriously, 
fall back
+               return this.getBrowserScaledImageElement( image, constraints );
        };
 
        /**
@@ -1152,6 +1165,7 @@
                                                        canvas.height = 
Math.round( canvas.width * video.videoHeight / video.videoWidth );
                                                        context = 
canvas.getContext( '2d' );
                                                        try {
+                                                               // More 
ridiculous exceptions, see the comment in #getTransformedCanvasElement
                                                                
context.drawImage( video, 0, 0, canvas.width, canvas.height );
                                                        } catch ( err ) {
                                                                
uw.eventFlowLogger.maybeLogFirefoxCanvasException( err, video );
diff --git a/resources/uw.EventFlowLogger.js b/resources/uw.EventFlowLogger.js
index 590b597..8802602 100644
--- a/resources/uw.EventFlowLogger.js
+++ b/resources/uw.EventFlowLogger.js
@@ -261,11 +261,10 @@
         *
         * @param {Error} err
         * @param {Object} img
-        * @throws {Error} Re-throws `err` if it's not a 
'NS_ERROR_NOT_AVAILABLE' exception
         */
        uw.EventFlowLogger.prototype.maybeLogFirefoxCanvasException = function 
( err, img ) {
                if ( err.name !== 'NS_ERROR_NOT_AVAILABLE' ) {
-                       throw err;
+                       return;
                }
 
                this.log( 'UploadWizardExceptionFlowEvent', {

-- 
To view, visit https://gerrit.wikimedia.org/r/309909
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie60421358d2178c0d8189018720021d1b3d58dbb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <matma....@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to