From 92acbdee4dc2be7c4fa35e59f8bec4e260e4fb56 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Thu, 10 Dec 2020 14:02:53 +1100 Subject: [PATCH] eval.php: add --ignore-errors option An option which causes eval.php to not exit on error. For interactive debugging. Change-Id: Ic1db8fd0e5fb4a757985ee8146a3f89a351060c7 --- maintenance/eval.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/maintenance/eval.php b/maintenance/eval.php index 98bad63b574..a0b8a8d262d 100644 --- a/maintenance/eval.php +++ b/maintenance/eval.php @@ -35,6 +35,7 @@ use MediaWiki\Logger\LoggerFactory; use MediaWiki\MediaWikiServices; $optionsWithArgs = [ 'd' ]; +$optionsWithoutArgs = [ 'ignore-errors' ]; require_once __DIR__ . "/CommandLineInc.php"; @@ -51,6 +52,8 @@ if ( isset( $options['d'] ) ) { } } +$__ignoreErrors = isset( $options['ignore-errors'] ); + $__useReadline = function_exists( 'readline_add_history' ) && Maintenance::posix_isatty( 0 /*STDIN*/ ); @@ -62,7 +65,7 @@ if ( $__useReadline ) { $__e = null; // PHP exception while ( ( $__line = Maintenance::readconsole() ) !== false ) { - if ( $__e && !preg_match( '/^(exit|die);?$/', $__line ) ) { + if ( !$__ignoreErrors && $__e && !preg_match( '/^(exit|die);?$/', $__line ) ) { // Internal state may be corrupted or fatals may occur later due // to some object not being set. Don't drop out of eval in case // lines were being pasted in (which would then get dumped to the shell). @@ -80,6 +83,14 @@ while ( ( $__line = Maintenance::readconsole() ) !== false ) { fwrite( STDERR, "Caught exception " . get_class( $__e ) . ": {$__e->getMessage()}\n" . $__e->getTraceAsString() . "\n" ); continue; + } catch ( Throwable $__e ) { + if ( $__ignoreErrors ) { + fwrite( STDERR, "Caught " . get_class( $__e ) . + ": {$__e->getMessage()}\n" . $__e->getTraceAsString() . "\n" ); + continue; + } else { + throw $__e; + } } if ( $__val === null ) { echo "\n";