Skip to content

Commit 5607d30

Browse files
committed
Harmonize catch blocks
1 parent 231db4b commit 5607d30

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/wp-includes/template.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,15 +1076,17 @@ static function ( int $level, string $message, ?string $file = null, ?int $line
10761076
*/
10771077
do_action( 'wp_finalized_template_enhancement_output_buffer', $filtered_output );
10781078
} catch ( Exception $exception ) {
1079-
// Emit to the error log.
1079+
// Emit to the error log as a warning not as an error to prevent halting execution.
1080+
$did_just_catch_exception = true;
10801081
trigger_error(
10811082
sprintf(
1082-
/* translators: %s is wp_finalized_template_enhancement_output_buffer */
1083-
__( 'Exception thrown during %s action: ' ) . $exception->getMessage(),
1084-
'wp_finalized_template_enhancement_output_buffer'
1085-
),
1083+
/* translators: %s is the exception class name */
1084+
__( 'Uncaught exception "%s" thrown:' ),
1085+
get_class( $exception )
1086+
) . ' ' . $exception->getMessage(),
10861087
E_USER_WARNING
10871088
);
1089+
$did_just_catch_exception = false;
10881090

10891091
// TODO: Should this also append the error to $filtered output if $display_errors? But it could make a sent header incorrect.
10901092
}

tests/phpunit/tests/template.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ public function data_provider_to_test_wp_finalize_template_enhancement_output_bu
10581058
'expected_processed' => false,
10591059
'expected_error_log' => array(
10601060
'PHP Warning: Uncaught exception "Exception" thrown: User error triggered: ERROR: Can this mistake be rectified during filter? in __FILE__ on line __LINE__',
1061-
'PHP Warning: Exception thrown during wp_finalized_template_enhancement_output_buffer action: User error triggered: ERROR: Can this mistake be rectified during action? in __FILE__ on line __LINE__',
1061+
'PHP Warning: Uncaught exception "Exception" thrown: User error triggered: ERROR: Can this mistake be rectified during action? in __FILE__ on line __LINE__',
10621062
),
10631063
'expected_displayed_errors' => array(
10641064
'<b>Error</b>: Uncaught exception "Exception" thrown: User error triggered: ERROR: Can this mistake be rectified during filter? in <b>__FILE__</b> on line <b>__LINE__</b>',
@@ -1075,7 +1075,7 @@ public function data_provider_to_test_wp_finalize_template_enhancement_output_bu
10751075
'expected_processed' => false,
10761076
'expected_error_log' => array(
10771077
'PHP Warning: Uncaught exception "Exception" thrown: I take exception to this filter! in __FILE__ on line __LINE__',
1078-
'PHP Warning: Exception thrown during wp_finalized_template_enhancement_output_buffer action: I take exception to this action! in __FILE__ on line __LINE__',
1078+
'PHP Warning: Uncaught exception "Exception" thrown: I take exception to this action! in __FILE__ on line __LINE__',
10791079
),
10801080
'expected_displayed_errors' => array(
10811081
'<b>Error</b>: Uncaught exception "Exception" thrown: I take exception to this filter! in <b>__FILE__</b> on line <b>__LINE__</b>',

0 commit comments

Comments
 (0)