Skip to content

Commit 44795bc

Browse files
author
tosite
committed
display preg_match ( error_get_last() ) errors.
1 parent dfacc4b commit 44795bc

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Search_Replace_Command.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,15 @@ public function __invoke( $args, $assoc_args ) {
203203

204204
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Preventing a warning when testing the regex.
205205
if ( false === @preg_match( $search_regex, '' ) ) {
206+
$error = error_get_last();
207+
$preg_error_message = ( ! empty( $error ) && array_key_exists( 'message', $error ) ) ? "\n{$error['message']}." : '';
206208
if ( $default_regex_delimiter ) {
207209
$flags_msg = $this->regex_flags ? "flags '$this->regex_flags'" : 'no flags';
208210
$msg = "The regex pattern '$old' with default delimiter 'chr(1)' and {$flags_msg} fails.";
209211
} else {
210212
$msg = "The regex '$search_regex' fails.";
211213
}
212-
WP_CLI::error( $msg );
214+
WP_CLI::error( $msg . $preg_error_message );
213215
}
214216
}
215217

0 commit comments

Comments
 (0)