Automattic\WooCommerce\Api\Infrastructure

GraphQLControllerBase::extract_previous_chainprivateWC 1.0

Walk the getPrevious() chain of a Throwable and return one entry per wrapped exception. Used in debug mode so that resolver-level wrappers (which bury the real cause behind a generic "INTERNAL_ERROR") still surface the underlying class/message/file/line/trace.

Method of the class: GraphQLControllerBase{}

No Hooks.

Returns

Array. array{class: string, message: string, file: string, line: int, trace: string[]}>

Usage

// private - for code of main (parent) class only
$result = $this->extract_previous_chain( $e ): array;
$e(Throwable) (required)
The outermost exception.

GraphQLControllerBase::extract_previous_chain() code WC 10.9.1

private function extract_previous_chain( \Throwable $e ): array {
	$chain = array();
	for ( $prev = $e->getPrevious(); null !== $prev; $prev = $prev->getPrevious() ) {
		$chain[] = array(
			'class'   => get_class( $prev ),
			'message' => $prev->getMessage(),
			'file'    => $prev->getFile(),
			'line'    => $prev->getLine(),
			'trace'   => explode( "\n", $prev->getTraceAsString() ),
		);
	}
	return $chain;
}