mirror of
https://hk.gh-proxy.com/https://github.com/wp-cli/profile-command.git
synced 2025-08-21 06:39:02 +08:00
Merge pull request #70 from runcommand/catch-exceptions
Catch hook Exceptions incrementally
This commit is contained in:
commit
e0af87e156
2 changed files with 28 additions and 8 deletions
|
@ -8,3 +8,14 @@ Feature: Profile a specific hook
|
||||||
| callback |
|
| callback |
|
||||||
| total |
|
| total |
|
||||||
And STDERR should be empty
|
And STDERR should be empty
|
||||||
|
|
||||||
|
Scenario: Profile a hook that has actions with output
|
||||||
|
Given a WP install
|
||||||
|
|
||||||
|
When I run `wp profile --hook=wp_head --fields=callback`
|
||||||
|
Then STDOUT should be a table containing rows:
|
||||||
|
| callback |
|
||||||
|
And STDOUT should not contain:
|
||||||
|
"""
|
||||||
|
<meta name="generator"
|
||||||
|
"""
|
||||||
|
|
|
@ -72,11 +72,7 @@ class Command {
|
||||||
WP_CLI::add_wp_hook( 'all', array( $this, 'wp_hook_begin' ) );
|
WP_CLI::add_wp_hook( 'all', array( $this, 'wp_hook_begin' ) );
|
||||||
WP_CLI::add_wp_hook( 'pre_http_request', array( $this, 'wp_request_begin' ) );
|
WP_CLI::add_wp_hook( 'pre_http_request', array( $this, 'wp_request_begin' ) );
|
||||||
WP_CLI::add_wp_hook( 'http_api_debug', array( $this, 'wp_request_end' ) );
|
WP_CLI::add_wp_hook( 'http_api_debug', array( $this, 'wp_request_end' ) );
|
||||||
try {
|
$this->load_wordpress_with_template();
|
||||||
$this->load_wordpress_with_template();
|
|
||||||
} catch( \Exception $e ) {
|
|
||||||
// pass through
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $this->focus_stage ) {
|
if ( $this->focus_stage ) {
|
||||||
$fields = array(
|
$fields = array(
|
||||||
|
@ -266,7 +262,11 @@ class Command {
|
||||||
$logger = new Logger( 'stage', 'bootstrap' );
|
$logger = new Logger( 'stage', 'bootstrap' );
|
||||||
$logger->start();
|
$logger->start();
|
||||||
}
|
}
|
||||||
WP_CLI::get_runner()->load_wordpress();
|
try {
|
||||||
|
WP_CLI::get_runner()->load_wordpress();
|
||||||
|
} catch( \Exception $e ) {
|
||||||
|
// pass through
|
||||||
|
}
|
||||||
if ( ! $this->focus_stage && ! $this->focus_hook ) {
|
if ( ! $this->focus_stage && ! $this->focus_hook ) {
|
||||||
$logger->stop();
|
$logger->stop();
|
||||||
$this->loggers[] = $logger;
|
$this->loggers[] = $logger;
|
||||||
|
@ -285,7 +285,11 @@ class Command {
|
||||||
$logger = new Logger( 'stage', 'main_query' );
|
$logger = new Logger( 'stage', 'main_query' );
|
||||||
$logger->start();
|
$logger->start();
|
||||||
}
|
}
|
||||||
wp();
|
try {
|
||||||
|
wp();
|
||||||
|
} catch( \Exception $e ) {
|
||||||
|
// pass through
|
||||||
|
}
|
||||||
if ( ! $this->focus_stage && ! $this->focus_hook ) {
|
if ( ! $this->focus_stage && ! $this->focus_hook ) {
|
||||||
$logger->stop();
|
$logger->stop();
|
||||||
$this->loggers[] = $logger;
|
$this->loggers[] = $logger;
|
||||||
|
@ -313,12 +317,17 @@ class Command {
|
||||||
$logger->start();
|
$logger->start();
|
||||||
}
|
}
|
||||||
ob_start();
|
ob_start();
|
||||||
require_once( ABSPATH . WPINC . '/template-loader.php' );
|
try {
|
||||||
|
require_once( ABSPATH . WPINC . '/template-loader.php' );
|
||||||
|
} catch( \Exception $e ) {
|
||||||
|
// pass through
|
||||||
|
}
|
||||||
ob_get_clean();
|
ob_get_clean();
|
||||||
if ( ! $this->focus_stage && ! $this->focus_hook ) {
|
if ( ! $this->focus_stage && ! $this->focus_hook ) {
|
||||||
$logger->stop();
|
$logger->stop();
|
||||||
$this->loggers[] = $logger;
|
$this->loggers[] = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue