Merge pull request #17491 from woocommerce/update/17101

wc_caught_exception method
This commit is contained in:
Claudiu Lodromanean 2017-11-01 09:31:57 -07:00 committed by GitHub
commit 9117414dae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 10 deletions

View File

@ -19,7 +19,7 @@ class WC_Order_Factory {
/** /**
* Get order. * Get order.
* *
* @param mixed $order_id (default: false) * @param mixed $order_id (default: false) Order ID to get.
* @return WC_Order|bool * @return WC_Order|bool
*/ */
public static function get_order( $order_id = false ) { public static function get_order( $order_id = false ) {
@ -46,13 +46,15 @@ class WC_Order_Factory {
try { try {
return new $classname( $order_id ); return new $classname( $order_id );
} catch ( Exception $e ) { } catch ( Exception $e ) {
wc_caught_exception( $e, __FUNCTION__, func_get_args() );
return false; return false;
} }
} }
/** /**
* Get order item. * Get order item.
* @param int *
* @param int $item_id Order item ID to get.
* @return WC_Order_Item|false if not found * @return WC_Order_Item|false if not found
*/ */
public static function get_order_item( $item_id = 0 ) { public static function get_order_item( $item_id = 0 ) {
@ -108,7 +110,7 @@ class WC_Order_Factory {
* Get the order ID depending on what was passed. * Get the order ID depending on what was passed.
* *
* @since 3.0.0 * @since 3.0.0
* @param mixed $order * @param mixed $order Order data to convert to an ID.
* @return int|bool false on failure * @return int|bool false on failure
*/ */
public static function get_order_id( $order ) { public static function get_order_id( $order ) {

View File

@ -34,11 +34,12 @@ function wc_do_deprecated_action( $action, $args, $deprecated_in, $replacement )
* Wrapper for deprecated functions so we can apply some extra logic. * Wrapper for deprecated functions so we can apply some extra logic.
* *
* @since 3.0.0 * @since 3.0.0
* @param string $function * @param string $function Function used.
* @param string $version * @param string $version Version the message was added in.
* @param string $replacement * @param string $replacement Replacement for the called function.
*/ */
function wc_deprecated_function( $function, $version, $replacement = null ) { function wc_deprecated_function( $function, $version, $replacement = null ) {
// @codingStandardsIgnoreStart
if ( is_ajax() ) { if ( is_ajax() ) {
do_action( 'deprecated_function_run', $function, $replacement, $version ); do_action( 'deprecated_function_run', $function, $replacement, $version );
$log_string = "The {$function} function is deprecated since version {$version}."; $log_string = "The {$function} function is deprecated since version {$version}.";
@ -47,18 +48,37 @@ function wc_deprecated_function( $function, $version, $replacement = null ) {
} else { } else {
_deprecated_function( $function, $version, $replacement ); _deprecated_function( $function, $version, $replacement );
} }
// @codingStandardsIgnoreEnd
} }
/**
* When catching an exception, this allows us to log it if unexpected.
*
* @since 3.3.0
* @param Exception $exception_object The exception object.
* @param string $function The function which threw exception.
* @param array $args The args passed to the function.
*/
function wc_caught_exception( $exception_object, $function = '', $args = array() ) {
// @codingStandardsIgnoreStart
$message = $exception_object->getMessage();
$message .= '. Args: ' . print_r( $args, true ) . '.';
do_action( 'woocommerce_caught_exception', $exception_object, $function, $args );
error_log( "Exception caught in {$function}. {$message}." );
// @codingStandardsIgnoreEnd
}
/** /**
* Wrapper for wc_doing_it_wrong. * Wrapper for wc_doing_it_wrong.
* *
* @since 3.0.0 * @since 3.0.0
* @param string $function * @param string $function Function used.
* @param string $version * @param string $message Message to log.
* @param string $replacement * @param string $version Version the message was added in.
*/ */
function wc_doing_it_wrong( $function, $message, $version ) { function wc_doing_it_wrong( $function, $message, $version ) {
// @codingStandardsIgnoreStart
$message .= ' Backtrace: ' . wp_debug_backtrace_summary(); $message .= ' Backtrace: ' . wp_debug_backtrace_summary();
if ( is_ajax() ) { if ( is_ajax() ) {
@ -67,6 +87,7 @@ function wc_doing_it_wrong( $function, $message, $version ) {
} else { } else {
_doing_it_wrong( $function, $message, $version ); _doing_it_wrong( $function, $message, $version );
} }
// @codingStandardsIgnoreEnd
} }
/** /**