Gergő Tisza has uploaded a new change for review.

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

Change subject: Log errors in thumb.php
......................................................................

Log errors in thumb.php

Change-Id: I3088cde2044a7ff00841e53ca252d0b222c8b518
---
M includes/filerepo/FileRepo.php
M includes/media/MediaTransformOutput.php
M thumb.php
3 files changed, 28 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/11/234811/1

diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php
index 7370c5c..8c3372a 100644
--- a/includes/filerepo/FileRepo.php
+++ b/includes/filerepo/FileRepo.php
@@ -1592,13 +1592,15 @@
         *
         * @param string $virtualUrl
         * @param array $headers Additional HTTP headers to send on success
+        * @param null $status Ugly hack to return a Status object while 
keeping B/C
         * @return bool Success
         */
-       public function streamFile( $virtualUrl, $headers = array() ) {
+       public function streamFile( $virtualUrl, $headers = array(), &$status = 
null ) {
                $path = $this->resolveToStoragePath( $virtualUrl );
                $params = array( 'src' => $path, 'headers' => $headers );
 
-               return $this->backend->streamFile( $params )->isOK();
+               $status = $this->backend->streamFile( $params );
+               return $status->isOK();
        }
 
        /**
diff --git a/includes/media/MediaTransformOutput.php 
b/includes/media/MediaTransformOutput.php
index 1dd8519..b3ca2c8 100644
--- a/includes/media/MediaTransformOutput.php
+++ b/includes/media/MediaTransformOutput.php
@@ -194,17 +194,21 @@
         * Stream the file if there were no errors
         *
         * @param array $headers Additional HTTP headers to send on success
+        * @param null $status Ugly hack to return a Status object while 
keeping B/C
         * @return bool Success
         */
-       public function streamFile( $headers = array() ) {
+       public function streamFile( $headers = array(), &$status = null ) {
                if ( !$this->path ) {
+                       $status = Status::newFatal( 'backend-fail-stream', '<no 
path>' );
                        return false;
                } elseif ( FileBackend::isStoragePath( $this->path ) ) {
                        $be = $this->file->getRepo()->getBackend();
-
-                       return $be->streamFile( array( 'src' => $this->path, 
'headers' => $headers ) )->isOK();
+                       $status = $be->streamFile( array( 'src' => $this->path, 
'headers' => $headers ) );
+                       return $status->isOK();
                } else { // FS-file
-                       return StreamFile::stream( $this->getLocalCopyPath(), 
$headers );
+                       $success = StreamFile::stream( 
$this->getLocalCopyPath(), $headers );
+                       $status = $success ? Status::newGood() : 
Status::newFatal( 'backend-fail-stream', $this->path );
+                       return $success;
                }
        }
 
diff --git a/thumb.php b/thumb.php
index eea6dda..05f195f 100644
--- a/thumb.php
+++ b/thumb.php
@@ -21,6 +21,8 @@
  * @ingroup Media
  */
 
+use MediaWiki\Logger\LoggerFactory;
+
 define( 'MW_NO_OUTPUT_COMPRESSION', 1 );
 require __DIR__ . '/includes/WebStart.php';
 
@@ -256,7 +258,8 @@
                wfThumbError( 400, 'The specified thumbnail parameters are not 
valid: ' . $e->getMessage() );
                return;
        } catch ( MWException $e ) {
-               wfThumbError( 500, $e->getHTML() );
+               wfThumbError( 500, $e->getHTML(), 'Exception caught while 
extracting thumb name',
+                       array( 'exception' => $e ) );
                return;
        }
 
@@ -303,11 +306,12 @@
        $thumbPath = $img->getThumbPath( $thumbName );
        if ( $img->getRepo()->fileExists( $thumbPath ) ) {
                $starttime = microtime( true );
-               $success = $img->getRepo()->streamFile( $thumbPath, $headers );
+               $success = $img->getRepo()->streamFile( $thumbPath, $headers, 
$status );
                $streamtime = microtime( true ) - $starttime;
 
                if ( !$success ) {
-                       wfThumbError( 500, 'Could not stream the file' );
+                       wfThumbError( 500, 'Could not stream the file', null, 
array( 'file' => $thumbName,
+                               'path' => $thumbPath, 'error' => 
$status->getWikiText() ) );
                } else {
                        RequestContext::getMain()->getStats()->timing( 
'media.thumbnail.stream', $streamtime );
                }
@@ -343,12 +347,13 @@
        }
 
        if ( $errorMsg !== false ) {
-               wfThumbError( $errorCode, $errorMsg );
+               wfThumbError( $errorCode, $errorMsg, null, array( 'file' => 
$thumbName, 'path' => $thumbPath ) );
        } else {
                // Stream the file if there were no errors
-               $success = $thumb->streamFile( $headers );
+               $success = $thumb->streamFile( $headers, $status );
                if ( !$success ) {
-                       wfThumbError( 500, 'Could not stream the file' );
+                       wfThumbError( 500, 'Could not stream the file', null, 
array(
+                               'file' => $thumbName, 'path' => $thumbPath, 
'error' => $status->getWikiText() ) );
                }
        }
 }
@@ -563,9 +568,12 @@
  *
  * @param int $status
  * @param string $msgHtml HTML
+ * @param string $msgText Short error description, for internal logging. 
Defaults to $msgHtml.
+ *   Only used for HTTP 500 errors.
+ * @param array $context Error context, for internal logging. Only used for 
HTTP 500 errors.
  * @return void
  */
-function wfThumbError( $status, $msgHtml ) {
+function wfThumbError( $status, $msgHtml, $msgText = null, $context = array() 
) {
        global $wgShowHostnames;
 
        header( 'Cache-Control: no-cache' );
@@ -576,6 +584,7 @@
                HttpStatus::header( 403 );
                header( 'Vary: Cookie' );
        } else {
+               LoggerFactory::getInstance( 'thumb' )->error( $msgText ?: 
$msgHtml, $context );
                HttpStatus::header( 500 );
        }
        if ( $wgShowHostnames ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3088cde2044a7ff00841e53ca252d0b222c8b518
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <gti...@wikimedia.org>

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

Reply via email to