Skip to content

Commit 5516e81

Browse files
authored
Merge pull request #471 from wp-cli/copilot/add-unexpected-output-logging
2 parents c04fd25 + dc695ee commit 5516e81

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

features/plugin-activate.feature

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,26 @@ Feature: Activate WordPress plugins
154154
Success:
155155
"""
156156
And the return code should be 0
157+
158+
Scenario: Activating a plugin that generates unexpected output shows the output in debug mode
159+
Given a wp-content/plugins/output-plugin.php file:
160+
"""
161+
<?php
162+
/**
163+
* Plugin Name: Output Plugin
164+
* Description: This plugin generates unexpected output during activation
165+
* Author: WP-CLI tests
166+
*/
167+
echo "Unexpected output from plugin activation";
168+
"""
169+
170+
When I try `wp plugin activate output-plugin --debug`
171+
Then STDERR should contain:
172+
"""
173+
Warning: Failed to activate plugin. The plugin generated unexpected output.
174+
"""
175+
And STDERR should contain:
176+
"""
177+
Debug (plugin): Unexpected output: Unexpected output from plugin activation
178+
"""
179+
And the return code should be 1

src/Plugin_Command.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,16 @@ public function activate( $args, $assoc_args = [] ) {
401401
$message = wp_strip_all_tags( $message );
402402
$message = str_replace( 'Error: ', '', $message );
403403
WP_CLI::warning( "Failed to activate plugin. {$message}" );
404+
// If the error is due to unexpected output, display it for debugging
405+
if ( 'unexpected_output' === $result->get_error_code() ) {
406+
/**
407+
* @var string $output
408+
*/
409+
$output = $result->get_error_data();
410+
if ( ! empty( $output ) ) {
411+
WP_CLI::debug( "Unexpected output: {$output}", 'plugin' );
412+
}
413+
}
404414
++$errors;
405415
} else {
406416
$this->active_output( $plugin->name, $plugin->file, $network_wide, 'activate' );

0 commit comments

Comments
 (0)