FormattedError
in package
This class is used for [default error formatting](error-handling.md).
It converts PHP exceptions to spec-compliant errors and provides tools for error debugging.
Tags
Table of Contents
- $internalErrorMessage : string
- addDebugEntries() : SerializableError
- Decorates spec-compliant $formattedError with debug entries according to $debug flags.
- createFromException() : SerializableError
- Convert any exception to a Automattic\WooCommerce\Vendor\GraphQL spec compliant array.
- prepareFormatter() : callable
- Prepares final error formatter taking in account $debug flags.
- printError() : string
- Prints a GraphQLError to a string, representing useful location information about the error's position in the source.
- printVar() : string
- setInternalErrorMessage() : void
- Set default error message for internal errors formatted using createFormattedError().
- toSafeTrace() : array<int, array{file?: string, line?: int, function?: string, call?: string}>
- Returns error trace as serializable array.
- getColumnOffset() : int
- highlightSourceAtLocation() : string
- Render a helpful description of the location of the error in the Automattic\WooCommerce\Vendor\GraphQL Source document.
- leftPad() : string
- spaces() : string
Properties
$internalErrorMessage
private
static string
$internalErrorMessage
= 'Internal server error'
Methods
addDebugEntries()
Decorates spec-compliant $formattedError with debug entries according to $debug flags.
public
static addDebugEntries(SerializableError $formattedError, Throwable $e, int $debugFlag) : SerializableError
Parameters
- $formattedError : SerializableError
- $e : Throwable
- $debugFlag : int
-
For available flags @see \Automattic\WooCommerce\Vendor\GraphQL\Error\DebugFlag
Tags
Return values
SerializableError —createFromException()
Convert any exception to a Automattic\WooCommerce\Vendor\GraphQL spec compliant array.
public
static createFromException(Throwable $exception[, int $debugFlag = DebugFlag::NONE ][, string|null $internalErrorMessage = null ]) : SerializableError
This method only exposes the exception message when the given exception implements the ClientAware interface, or when debug flags are passed.
For a list of available debug flags @see \Automattic\WooCommerce\Vendor\GraphQL\Error\DebugFlag constants.
Parameters
- $exception : Throwable
- $debugFlag : int = DebugFlag::NONE
- $internalErrorMessage : string|null = null
Return values
SerializableError —prepareFormatter()
Prepares final error formatter taking in account $debug flags.
public
static prepareFormatter(callable|null $formatter, int $debug) : callable
If initial formatter is not set, FormattedError::createFromException is used.
Parameters
- $formatter : callable|null
- $debug : int
Tags
Return values
callable —printError()
Prints a GraphQLError to a string, representing useful location information about the error's position in the source.
public
static printError(Error $error) : string
Parameters
- $error : Error
Return values
string —printVar()
public
static printVar(mixed $var) : string
Parameters
- $var : mixed
Return values
string —setInternalErrorMessage()
Set default error message for internal errors formatted using createFormattedError().
public
static setInternalErrorMessage(string $msg) : void
This value can be overridden by passing 3rd argument to createFormattedError().
Parameters
- $msg : string
Return values
void —toSafeTrace()
Returns error trace as serializable array.
public
static toSafeTrace(Throwable $error) : array<int, array{file?: string, line?: int, function?: string, call?: string}>
Parameters
- $error : Throwable
Return values
array<int, array{file?: string, line?: int, function?: string, call?: string}> —getColumnOffset()
private
static getColumnOffset(Source $source, SourceLocation $location) : int
Parameters
- $source : Source
- $location : SourceLocation
Return values
int —highlightSourceAtLocation()
Render a helpful description of the location of the error in the Automattic\WooCommerce\Vendor\GraphQL Source document.
private
static highlightSourceAtLocation(Source $source, SourceLocation $location) : string
Parameters
- $source : Source
- $location : SourceLocation
Return values
string —leftPad()
private
static leftPad(int $length, string $str) : string
Parameters
- $length : int
- $str : string
Return values
string —spaces()
private
static spaces(int $length) : string
Parameters
- $length : int
