Merge "Try not to discard Excimer timeout exceptions"

This commit is contained in:
jenkins-bot 2022-02-03 00:28:16 +00:00 committed by Gerrit Code Review
commit 2becc606d3
36 changed files with 215 additions and 94 deletions

View file

@ -645,6 +645,7 @@ $wgAutoloadLocalClasses = [
'IdentityCollation' => __DIR__ . '/includes/collation/IdentityCollation.php',
'ImageBuilder' => __DIR__ . '/maintenance/rebuildImages.php',
'ImageGalleryBase' => __DIR__ . '/includes/gallery/ImageGalleryBase.php',
'ImageGalleryClassNotFoundException' => __DIR__ . '/includes/gallery/ImageGalleryClassNotFoundException.php',
'ImageHandler' => __DIR__ . '/includes/media/ImageHandler.php',
'ImageHistoryList' => __DIR__ . '/includes/page/ImageHistoryList.php',
'ImageHistoryPseudoPager' => __DIR__ . '/includes/page/ImageHistoryPseudoPager.php',

View file

@ -184,7 +184,7 @@ class CategoryViewer extends ContextSource {
$mode = $this->getRequest()->getVal( 'gallerymode', null );
try {
$this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() );
} catch ( Exception $e ) {
} catch ( ImageGalleryClassNotFoundException $e ) {
// User specified something invalid, fallback to default.
$this->gallery = ImageGalleryBase::factory( false, $this->getContext() );
}

View file

@ -28,6 +28,7 @@ use Wikimedia\Assert\Assert;
use Wikimedia\Rdbms\Database;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\ILoadBalancer;
use Wikimedia\RequestTimeout\TimeoutException;
/**
* @author Addshore
@ -481,6 +482,8 @@ class NameTableStore {
},
IDatabase::ATOMIC_CANCELABLE
);
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $ex ) {
$this->logger->error(
'Re-insertion of name into table ' . $this->table . ' failed: ' . $ex->getMessage()

View file

@ -27,6 +27,7 @@ use MediaWiki\Permissions\PermissionStatus;
use MediaWiki\Revision\RevisionRecord;
use MediaWiki\User\UserOptionsLookup;
use MediaWiki\Watchlist\WatchlistManager;
use Wikimedia\RequestTimeout\TimeoutException;
/**
* Handle page deletion
@ -533,10 +534,13 @@ class DeleteAction extends FormlessAction {
try {
return $this->getArticle()->getPage()->getAutoDeleteReason();
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
# if a page is horribly broken, we still want to be able to
# delete it. So be lenient about errors here.
// TODO Find out when this can happen and narrow the type in the `catch` clause.
# For example, WMF logs show MWException thrown from
# ContentHandler::checkModelID().
MWExceptionHandler::logException( $e );
return '';
}

View file

@ -27,6 +27,7 @@ use MediaWiki\Revision\RevisionRecord;
use MediaWiki\Revision\RevisionStore;
use MediaWiki\Revision\SlotRecord;
use MediaWiki\Revision\SlotRoleRegistry;
use Wikimedia\RequestTimeout\TimeoutException;
/**
* @ingroup API
@ -565,6 +566,8 @@ class ApiComparePages extends ApiBase {
}
try {
$content = $oldContent->replaceSection( $section, $content, '' );
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $ex ) {
// Probably a content model mismatch.
$content = null;

View file

@ -35,6 +35,7 @@ use MediaWiki\Revision\SlotRecord;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Wikimedia\Rdbms\Database;
use Wikimedia\RequestTimeout\TimeoutException;
use Wikimedia\ScopedCallback;
/**
@ -574,6 +575,8 @@ class MessageCache implements LoggerAwareInterface {
$rev = $revisions[$row->rev_id] ?? null;
$content = $rev ? $rev->getContent( SlotRecord::MAIN ) : null;
$text = $this->getMessageTextFromContent( $content );
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $ex ) {
$text = false;
}

View file

@ -17,7 +17,7 @@
*
* @file
*/
use Cdb\Exception;
use Cdb\Exception as CdbException;
use Cdb\Reader;
use Cdb\Writer;
@ -57,7 +57,7 @@ class LCStoreCDB implements LCStore {
if ( is_file( $fileName ) ) {
try {
$this->readers[$code] = Reader::open( $fileName );
} catch ( Exception $e ) {
} catch ( CdbException $e ) {
wfDebug( __METHOD__ . ": unable to open cdb file for reading" );
}
}
@ -69,7 +69,7 @@ class LCStoreCDB implements LCStore {
$value = false;
try {
$value = $this->readers[$code]->get( $key );
} catch ( Exception $e ) {
} catch ( CdbException $e ) {
wfDebug( __METHOD__ . ": \Cdb\Exception caught, error message was "
. $e->getMessage() );
}
@ -94,7 +94,7 @@ class LCStoreCDB implements LCStore {
try {
$this->writer = Writer::open( $this->getFileName( $code ) );
} catch ( Exception $e ) {
} catch ( CdbException $e ) {
throw new MWException( $e->getMessage() );
}
$this->currentLang = $code;
@ -104,7 +104,7 @@ class LCStoreCDB implements LCStore {
// Close the writer
try {
$this->writer->close();
} catch ( Exception $e ) {
} catch ( CdbException $e ) {
throw new MWException( $e->getMessage() );
}
$this->writer = null;
@ -118,7 +118,7 @@ class LCStoreCDB implements LCStore {
}
try {
$this->writer->set( $key, serialize( $value ) );
} catch ( Exception $e ) {
} catch ( CdbException $e ) {
throw new MWException( $e->getMessage() );
}
}

View file

@ -21,6 +21,7 @@
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Wikimedia\RequestTimeout\TimeoutException;
/**
* @defgroup ExternalStorage ExternalStorage
@ -147,6 +148,8 @@ class ExternalStoreAccess implements LoggerAwareInterface {
"No URL returned by storage medium ($storeUrl)"
);
}
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $ex ) {
$error = $ex;
$msg = 'caught ' . get_class( $error ) . ' exception: ' . $error->getMessage();

View file

@ -111,7 +111,7 @@ abstract class ImageGalleryBase extends ContextSource {
* @param string|bool $mode Mode to use. False to use the default
* @param IContextSource|null $context
* @return ImageGalleryBase
* @throws MWException
* @throws ImageGalleryClassNotFoundException
*/
public static function factory( $mode = false, IContextSource $context = null ) {
self::loadModes();
@ -129,7 +129,7 @@ abstract class ImageGalleryBase extends ContextSource {
$class = self::$modeMapping[$mode];
return new $class( $mode, $context );
} else {
throw new MWException( "No gallery class registered for mode $mode" );
throw new ImageGalleryClassNotFoundException( "No gallery class registered for mode $mode" );
}
}

View file

@ -0,0 +1,9 @@
<?php
/**
* Class for exceptions thrown by ImageGalleryBase::factory().
*
* @since 1.38
*/
class ImageGalleryClassNotFoundException extends MWException {
}

View file

@ -229,7 +229,7 @@ abstract class HTMLFormField {
default:
throw new MWException( "Unknown operation" );
}
} catch ( Exception $ex ) {
} catch ( MWException $ex ) {
throw new MWException(
"Invalid hide-if or disable-if specification for $this->mName: " .
$ex->getMessage() . " in " . var_export( $origParams, true ),

View file

@ -1,5 +1,7 @@
<?php
use Wikimedia\RequestTimeout\TimeoutException;
/**
* A field that will contain a date and/or time
*
@ -135,6 +137,8 @@ class HTMLDateTimeField extends HTMLTextField {
try {
$date = new DateTime( $value, new DateTimeZone( 'GMT' ) );
return $date->getTimestamp();
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $ex ) {
return false;
}

View file

@ -21,6 +21,7 @@
* @defgroup JobQueue JobQueue
*/
use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
use Wikimedia\RequestTimeout\TimeoutException;
use Wikimedia\UUID\GlobalIdGenerator;
/**
@ -407,6 +408,8 @@ abstract class JobQueue {
$this->incrStats( 'dupe_pops', $job->getType() );
$job = DuplicateJob::newFromJob( $job ); // convert to a no-op
}
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
// don't lose jobs over this
}

View file

@ -32,6 +32,7 @@ use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
use MediaWiki\User\UserIdentity;
use Wikimedia\Assert\Assert;
use Wikimedia\RequestTimeout\TimeoutException;
/**
* Internationalisation code
@ -2083,6 +2084,8 @@ class Language {
$date = new DateTime( $ts, new DateTimeZone( 'UTC' ) );
$date->setTimezone( $userTZ );
return $date->format( 'YmdHis' );
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
// Unrecognized timezone, default to 'Offset' with the stored offset.
$data[0] = 'Offset';

View file

@ -24,6 +24,7 @@ use MediaWiki\MediaWikiServices;
use MediaWiki\Message\UserGroupMembershipParam;
use MediaWiki\Page\PageReference;
use MediaWiki\Page\PageReferenceValue;
use Wikimedia\RequestTimeout\TimeoutException;
/**
* The Message class deals with fetching and processing of interface message
@ -1012,20 +1013,26 @@ class Message implements MessageSpecifier, Serializable {
* @return string
*/
public function __toString() {
// PHP doesn't allow __toString to throw exceptions and will
// PHP before 7.4.0 doesn't allow __toString to throw exceptions and will
// trigger a fatal error if it does. So, catch any exceptions.
try {
return $this->format( self::FORMAT_PARSE );
} catch ( Exception $ex ) {
if ( version_compare( PHP_VERSION, '7.4.0', '<' ) ) {
try {
trigger_error( "Exception caught in " . __METHOD__ . " (message " . $this->key . "): "
. $ex, E_USER_WARNING );
return $this->format( self::FORMAT_PARSE );
} catch ( TimeoutException $e ) {
// Fatal is OK in this case
throw $e;
} catch ( Exception $ex ) {
// Doh! Cause a fatal error after all?
}
try {
trigger_error( "Exception caught in " . __METHOD__ . " (message " . $this->key . "): "
. $ex, E_USER_WARNING );
} catch ( Exception $ex ) {
// Doh! Cause a fatal error after all?
}
return '⧼' . htmlspecialchars( $this->key ) . '⧽';
return '⧼' . htmlspecialchars( $this->key ) . '⧽';
}
} else {
return $this->format( self::FORMAT_PARSE );
}
}

View file

@ -24,6 +24,7 @@
use Psr\Log\LoggerInterface;
use Wikimedia\AtEase\AtEase;
use Wikimedia\RequestTimeout\TimeoutException;
/**
* @brief Class for an OpenStack Swift (or Ceph RGW) based file backend.
@ -763,6 +764,8 @@ class SwiftFileBackend extends FileBackendStore {
$timestamp = new MWTimestamp( $ts );
return $timestamp->getTimestamp( $format );
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
throw new FileBackendError( $e->getMessage() );
}

View file

@ -21,6 +21,7 @@
* @ingroup FileBackend
*/
use Psr\Log\LoggerInterface;
use Wikimedia\RequestTimeout\TimeoutException;
/**
* FileBackend helper class for representing operations.
@ -507,6 +508,8 @@ abstract class FileOp {
try {
$this->logger->error( static::class .
" failed: " . FormatJson::encode( $params ) );
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
// bad config? debug log error?
}

View file

@ -23,6 +23,7 @@
use Liuggio\StatsdClient\Entity\StatsdData;
use Liuggio\StatsdClient\Entity\StatsdDataInterface;
use Liuggio\StatsdClient\StatsdClient;
use Wikimedia\RequestTimeout\TimeoutException;
/**
* A statsd client that applies the sampling rate to the data items before sending them.
@ -115,6 +116,8 @@ class SamplingStatsdClient extends StatsdClient {
$written += $this->getSender()->write( $fp, $message );
}
$this->getSender()->close( $fp );
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
$this->throwException( $e );
}

View file

@ -23,6 +23,7 @@
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
use Wikimedia\RequestTimeout\TimeoutException;
use Wikimedia\XMPReader\Reader as XMPReader;
/**
@ -69,6 +70,8 @@ class BitmapMetadataHandler {
private function doApp13( $app13 ) {
try {
$this->iptcType = JpegMetadataExtractor::doPSIR( $app13 );
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
// Error reading the iptc hash information.
// This probably means the App13 segment is something other than what we expect.

View file

@ -71,7 +71,7 @@ class BmpHandler extends BitmapHandler {
try {
$w = wfUnpack( 'V', $w, 4 );
$h = wfUnpack( 'V', $h, 4 );
} catch ( Exception $e ) {
} catch ( MWException $e ) {
return [];
}

View file

@ -23,6 +23,7 @@
use MediaWiki\MediaWikiServices;
use MediaWiki\Shell\Shell;
use Wikimedia\RequestTimeout\TimeoutException;
use Wikimedia\ScopedCallback;
/**
@ -415,6 +416,8 @@ class SvgHandler extends ImageHandler {
try {
$svgReader = new SVGReader( $filename );
$metadata += $svgReader->getMetadata();
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) { // @todo SVG specific exceptions
// File not found, broken, etc.
$metadata['error'] = [

View file

@ -40,6 +40,7 @@ use Wikimedia\Message\ITextFormatter;
use Wikimedia\Message\MessageValue;
use Wikimedia\Rdbms\ILoadBalancer;
use Wikimedia\Rdbms\LBFactory;
use Wikimedia\RequestTimeout\TimeoutException;
use WikiPage;
/**
@ -574,6 +575,8 @@ class DeletePage {
}
try {
$content = $page->getContent( RevisionRecord::RAW );
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $ex ) {
wfLogWarning( __METHOD__ . ': failed to load content during deletion! '
. $ex->getMessage() );
@ -838,6 +841,8 @@ class DeletePage {
public function doDeleteUpdates( WikiPage $page, RevisionRecord $revRecord ): void {
try {
$countable = $page->isCountable();
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $ex ) {
// fallback for deleting broken pages for which we cannot load the content for
// some reason. Note that doDeleteArticleReal() already logged this problem.

View file

@ -53,6 +53,7 @@ use Wikimedia\NonSerializable\NonSerializableTrait;
use Wikimedia\Rdbms\FakeResultWrapper;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\ILoadBalancer;
use Wikimedia\RequestTimeout\TimeoutException;
/**
* Class representing a MediaWiki article and history.
@ -3274,6 +3275,8 @@ class WikiPage implements Page, IDBAccessObject, PageRecord {
try {
$rev = $this->getRevisionRecord();
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $ex ) {
// If we can't load the content, something is wrong. Perhaps that's why
// the user is trying to delete the page, so let's not fail in that case.

View file

@ -5039,7 +5039,7 @@ class Parser {
try {
$ig = ImageGalleryBase::factory( $mode );
} catch ( Exception $e ) {
} catch ( ImageGalleryClassNotFoundException $e ) {
// If invalid type set, fallback to default.
$ig = ImageGalleryBase::factory( false );
}

View file

@ -430,6 +430,7 @@ LUA;
* Try to make sure that locks get released (even with exceptions and fatals)
*/
public static function releaseAll() {
$e = null;
foreach ( self::$active as $poolCounter ) {
try {
if ( $poolCounter->slot !== null ) {
@ -438,5 +439,8 @@ LUA;
} catch ( Exception $e ) {
}
}
if ( $e ) {
throw $e;
}
}
}

View file

@ -62,6 +62,7 @@ use Title;
use UnexpectedValueException;
use User;
use UserGroupMembership;
use Wikimedia\RequestTimeout\TimeoutException;
use Xml;
/**
@ -971,6 +972,8 @@ class DefaultPreferencesFactory implements PreferencesFactory {
$userTZ = new DateTimeZone( $tz[2] );
$minDiff = floor( $userTZ->getOffset( new DateTime( 'now' ) ) / 60 );
$tzSetting = "ZoneInfo|$minDiff|{$tz[2]}";
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
// User has an invalid time zone set. Fall back to just using the offset
$tz[0] = 'Offset';

View file

@ -32,6 +32,7 @@ use Wikimedia\DependencyStore\KeyValueDependencyStore;
use Wikimedia\Minify\CSSMin;
use Wikimedia\Minify\JavaScriptMinifier;
use Wikimedia\Rdbms\DBConnectionError;
use Wikimedia\RequestTimeout\TimeoutException;
use Wikimedia\ScopedCallback;
use Wikimedia\Timestamp\ConvertibleTimestamp;
use Wikimedia\WrappedString;
@ -221,6 +222,8 @@ class ResourceLoader implements LoggerAwareInterface {
$data = ( $filter === 'minify-css' )
? CSSMin::minify( $data )
: JavaScriptMinifier::minify( $data );
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
MWExceptionHandler::logException( $e );
return null;
@ -713,6 +716,8 @@ class ResourceLoader implements LoggerAwareInterface {
$hashes = array_map( function ( $module ) use ( $context ) {
try {
return $this->getModule( $module )->getVersionHash( $context );
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
// If modules fail to compute a version, don't fail the request (T152266)
// and still compute versions of other modules.
@ -777,84 +782,94 @@ class ResourceLoader implements LoggerAwareInterface {
$responseTime = $this->measureResponseTime();
// Find out which modules are missing and instantiate the others
$modules = [];
$missing = [];
foreach ( $context->getModules() as $name ) {
$module = $this->getModule( $name );
if ( $module ) {
// Do not allow private modules to be loaded from the web.
// This is a security issue, see T36907.
if ( $module->getGroup() === ResourceLoaderModule::GROUP_PRIVATE ) {
// Not a serious error, just means something is trying to access it (T101806)
$this->logger->debug( "Request for private module '$name' denied" );
$this->errors[] = "Cannot build private module \"$name\"";
continue;
$response = '';
try { // TimeoutException
// Find out which modules are missing and instantiate the others
$modules = [];
$missing = [];
foreach ( $context->getModules() as $name ) {
$module = $this->getModule( $name );
if ( $module ) {
// Do not allow private modules to be loaded from the web.
// This is a security issue, see T36907.
if ( $module->getGroup() === ResourceLoaderModule::GROUP_PRIVATE ) {
// Not a serious error, just means something is trying to access it (T101806)
$this->logger->debug( "Request for private module '$name' denied" );
$this->errors[] = "Cannot build private module \"$name\"";
continue;
}
$modules[$name] = $module;
} else {
$missing[] = $name;
}
}
try {
// Preload for getCombinedVersion() and for batch makeModuleResponse()
$this->preloadModuleInfo( array_keys( $modules ), $context );
}
catch ( TimeoutException $e ) {
throw $e;
}
catch ( Exception $e ) {
$this->outputErrorAndLog( $e, 'Preloading module info failed: {exception}' );
}
// Combine versions to propagate cache invalidation
$versionHash = '';
try {
$versionHash = $this->getCombinedVersion( $context, array_keys( $modules ) );
}
catch ( TimeoutException $e ) {
throw $e;
}
catch ( Exception $e ) {
$this->outputErrorAndLog( $e, 'Calculating version hash failed: {exception}' );
}
// See RFC 2616 § 3.11 Entity Tags
// https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.11
$etag = 'W/"' . $versionHash . '"';
// Try the client-side cache first
if ( $this->tryRespondNotModified( $context, $etag ) ) {
return; // output handled (buffers cleared)
}
// Use file cache if enabled and available...
if ( $this->config->get( 'UseFileCache' ) ) {
$fileCache = ResourceFileCache::newFromContext( $context );
if ( $this->tryRespondFromFileCache( $fileCache, $context, $etag ) ) {
return; // output handled
}
$modules[$name] = $module;
} else {
$missing[] = $name;
$fileCache = null;
}
}
try {
// Preload for getCombinedVersion() and for batch makeModuleResponse()
$this->preloadModuleInfo( array_keys( $modules ), $context );
} catch ( Exception $e ) {
$this->outputErrorAndLog( $e, 'Preloading module info failed: {exception}' );
}
// Generate a response
$response = $this->makeModuleResponse( $context, $modules, $missing );
// Combine versions to propagate cache invalidation
$versionHash = '';
try {
$versionHash = $this->getCombinedVersion( $context, array_keys( $modules ) );
} catch ( Exception $e ) {
$this->outputErrorAndLog( $e, 'Calculating version hash failed: {exception}' );
}
// See RFC 2616 § 3.11 Entity Tags
// https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.11
$etag = 'W/"' . $versionHash . '"';
// Try the client-side cache first
if ( $this->tryRespondNotModified( $context, $etag ) ) {
return; // output handled (buffers cleared)
}
// Use file cache if enabled and available...
if ( $this->config->get( 'UseFileCache' ) ) {
$fileCache = ResourceFileCache::newFromContext( $context );
if ( $this->tryRespondFromFileCache( $fileCache, $context, $etag ) ) {
return; // output handled
// Capture any PHP warnings from the output buffer and append them to the
// error list if we're in debug mode.
if ( $context->getDebug() ) {
$warnings = ob_get_contents();
if ( strlen( $warnings ) ) {
$this->errors[] = $warnings;
}
}
} else {
$fileCache = null;
}
// Generate a response
$response = $this->makeModuleResponse( $context, $modules, $missing );
// Capture any PHP warnings from the output buffer and append them to the
// error list if we're in debug mode.
if ( $context->getDebug() ) {
$warnings = ob_get_contents();
if ( strlen( $warnings ) ) {
$this->errors[] = $warnings;
}
}
// Consider saving the response to file cache (unless there are errors).
if ( $fileCache &&
!$this->errors &&
$missing === [] &&
ResourceFileCache::useFileCache( $context )
) {
if ( $fileCache->isCacheWorthy() ) {
// There were enough hits, save the response to the cache
$fileCache->saveText( $response );
} else {
$fileCache->incrMissesRecent( $context->getRequest() );
// Consider saving the response to file cache (unless there are errors).
if ( $fileCache && !$this->errors && $missing === [] &&
ResourceFileCache::useFileCache( $context ) ) {
if ( $fileCache->isCacheWorthy() ) {
// There were enough hits, save the response to the cache
$fileCache->saveText( $response );
} else {
$fileCache->incrMissesRecent( $context->getRequest() );
}
}
} catch ( TimeoutException $e ) {
$this->outputErrorAndLog( $e, "Request timed out" );
}
$this->sendResponseHeaders( $context, $etag, (bool)$this->errors, $this->extraHeaders );
@ -1211,6 +1226,8 @@ MESSAGE;
$out .= $strContent;
}
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
$this->outputErrorAndLog( $e, 'Generating module package failed: {exception}' );

View file

@ -23,6 +23,7 @@
use MediaWiki\Languages\LanguageFallback;
use MediaWiki\MediaWikiServices;
use Wikimedia\Minify\CSSMin;
use Wikimedia\RequestTimeout\TimeoutException;
/**
* Module based on local JavaScript/CSS files.
@ -1416,6 +1417,8 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
$fileInfo['content'],
[ 'minifyTemplate' => !$context->getDebug() ]
);
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
$msg = "Error parsing file '$fileName' in module '{$this->getName()}': " .
$e->getMessage();

View file

@ -27,6 +27,7 @@ use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Wikimedia\RelPath;
use Wikimedia\RequestTimeout\TimeoutException;
/**
* Abstraction for ResourceLoader modules, with name registration and maxage functionality.
@ -581,6 +582,8 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
self::getRelativePaths( $curFileRefs ),
self::getRelativePaths( $this->getFileDependencies( $context ) )
);
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
$this->getLogger()->warning(
__METHOD__ . ": failed to update dependencies: {$e->getMessage()}",
@ -1040,6 +1043,8 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
// Ignore compiler warnings (T77169)
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
@$parser->parse( $contents, $fileName, 1 );
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
return $e->getMessage();
}

View file

@ -20,6 +20,8 @@
* @author Roan Kattouw
*/
use Wikimedia\RequestTimeout\TimeoutException;
/**
* Module for ResourceLoader initialization.
*
@ -168,6 +170,8 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
// don't require on-demand loading of more information.
try {
$resourceLoader->preloadModuleInfo( $moduleNames, $context );
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
// Don't fail the request (T152266)
// Also print the error in the main output
@ -214,6 +218,8 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
// length ResourceLoader::HASH_LENGTH (or empty string).
// The getVersionHash method is final and is covered by tests, as is makeHash().
$versionHash = $module->getVersionHash( $context );
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
// Don't fail the request (T152266)
// Also print the error in the main output

View file

@ -1,5 +1,7 @@
<?php
use Wikimedia\RequestTimeout\TimeoutException;
/**
* Utility for importing site entries from XML.
* For the expected format of the input, see docs/sitelist.md and docs/sitelist-1.0.xsd.
@ -141,6 +143,8 @@ class SiteImporter {
}
$sites[$key] = $site;
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $ex ) {
$this->handleException( $ex );
}

View file

@ -23,6 +23,7 @@
*/
use Wikimedia\Rdbms\ILoadBalancer;
use Wikimedia\RequestTimeout\TimeoutException;
/**
* Special page to direct the user to a random page
@ -255,6 +256,8 @@ class SpecialRandomInCategory extends FormSpecialPage {
if ( !$this->minTimestamp || !$this->maxTimestamp ) {
try {
list( $this->minTimestamp, $this->maxTimestamp ) = $this->getMinAndMaxForCat( $this->category );
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
// Possibly no entries in category.
return false;

View file

@ -21,6 +21,7 @@
*/
use MediaWiki\Http\HttpRequestFactory;
use Wikimedia\RequestTimeout\TimeoutException;
/**
* Web access for files temporarily stored by UploadStash.
@ -432,7 +433,10 @@ class SpecialUploadStash extends UnlistedSpecialPage {
$this->msg( 'uploadstash-thumbnail' )->text()
)
)->escaped();
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
MWExceptionHandler::logException( $e );
}
$fileListItemsHtml .= Html::rawElement( 'li', [], $itemHtml );
}

View file

@ -20,6 +20,7 @@
use MediaWiki\Linker\LinkRenderer;
use MediaWiki\MediaWikiServices;
use Wikimedia\RequestTimeout\TimeoutException;
/**
* Sub class of HTMLForm that provides the form section of SpecialUpload
@ -292,6 +293,8 @@ class UploadForm extends HTMLForm {
$stash = $this->localRepo->getUploadStash( $this->getUser() );
try {
$file = $stash->getFile( $this->mSessionKey );
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
$file = null;
}

View file

@ -160,7 +160,7 @@ class NewFilesPager extends RangeChronologicalPager {
$mode = $this->getRequest()->getVal( 'gallerymode', null );
try {
$this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() );
} catch ( Exception $e ) {
} catch ( ImageGalleryClassNotFoundException $e ) {
// User specified something invalid, fallback to default.
$this->gallery = ImageGalleryBase::factory( false, $this->getContext() );
}

View file

@ -26,6 +26,7 @@ use DateInterval;
use DateTime;
use DateTimeZone;
use Exception;
use Wikimedia\RequestTimeout\TimeoutException;
/**
* Utility class to parse the TimeCorrection string value.
@ -171,6 +172,8 @@ class UserTimeCorrection {
$this->offset = floor( $this->timeZone->getOffset( $this->date ) / 60 );
$this->valid = true;
return;
} catch ( TimeoutException $e ) {
throw $e;
} catch ( Exception $e ) {
// Not a valid/known timezone.
// Fall back to any specified offset