WooCommerce Code Reference

Error extends Exception
in package
implements JsonSerializable, ClientAware, ProvidesExtensions

Describes an Error found during the parse, validate, or execute phases of performing a Automattic\WooCommerce\Vendor\GraphQL operation. In addition to a message and stack trace, it also includes information about the locations in a Automattic\WooCommerce\Vendor\GraphQL document and/or execution result that correspond to the Error.

When the error was caused by an exception thrown in resolver, original exception is available via getPrevious().

Also read related docs on error handling

Class extends standard PHP \Exception, so all standard methods of base \Exception class are available in addition to those listed below.

Tags
see
ErrorTest

Interfaces, Classes and Traits

JsonSerializable
ClientAware
Implementing ClientAware allows graphql-php to decide if this error is safe to be shown to clients.
ProvidesExtensions
Implementing HasExtensions allows this error to provide additional data to clients.

Table of Contents

$nodes  : array<string|int, mixed>|null
An array of Automattic\WooCommerce\Vendor\GraphQL AST Nodes corresponding to this error.
$path  : array<string|int, mixed>|null
An array describing the JSON-path into the execution response which corresponds to this error. Only included for errors during execution.
$unaliasedPath  : array<string|int, mixed>|null
An array describing the JSON-path into the execution response which corresponds to this error. Only included for errors during execution.
$extensions  : array<string|int, mixed>|null
$isClientSafe  : bool
$locations  : array<string|int, mixed>
Lazily initialized.
$positions  : array<string|int, mixed>|null
$source  : Source|null
The source Automattic\WooCommerce\Vendor\GraphQL document for the first location of this error.
__construct()  : mixed
__toString()  : string
createLocatedError()  : Error
Given an arbitrary Error, presumably thrown while attempting to execute a Automattic\WooCommerce\Vendor\GraphQL operation, produce a new GraphQLError aware of the location in the document responsible for the original Error.
getExtensions()  : array<string, mixed>|null
Data to include within the "extensions" key of the formatted error.
getLocations()  : array<int, SourceLocation>
An array of locations within the source Automattic\WooCommerce\Vendor\GraphQL document which correspond to this error.
getNodes()  : array<string|int, Node>|null
getPath()  : array<int, int|string>|null
Returns an array describing the path from the root value to the field which produced this error.
getPositions()  : array<int, int>
getSource()  : Source|null
getUnaliasedPath()  : array<int, int|string>|null
Returns an array describing the path from the root value to the field which produced this error.
isClientSafe()  : bool
Is it safe to show the error message to clients?
jsonSerialize()  : array<string, mixed>
Specify data which should be serialized to JSON.
isLocated()  : bool

Properties

$nodes

An array of Automattic\WooCommerce\Vendor\GraphQL AST Nodes corresponding to this error.

public array<string|int, mixed>|null $nodes

$path

An array describing the JSON-path into the execution response which corresponds to this error. Only included for errors during execution.

public array<string|int, mixed>|null $path

When fields are aliased, the path includes aliases.

$unaliasedPath

An array describing the JSON-path into the execution response which corresponds to this error. Only included for errors during execution.

public array<string|int, mixed>|null $unaliasedPath

This will never include aliases.

$source

The source Automattic\WooCommerce\Vendor\GraphQL document for the first location of this error.

private Source|null $source

Note that if this Error represents more than one node, the source may not represent nodes after the first node.

Methods

__construct()

public __construct([string $message = '' ][, iteratable<array-key, \Automattic\WooCommerce\Vendor\GraphQL\Language\AST\Node|null>|Node|null $nodes = null ][, Source|null $source = null ][, array<int, int>|null $positions = null ][, array<int, int|string>|null $path = null ][, Throwable|null $previous = null ][, array<string, mixed>|null $extensions = null ][, array<int, int|string>|null $unaliasedPath = null ]) : mixed
Parameters
$message : string = ''
$nodes : iteratable<array-key, \Automattic\WooCommerce\Vendor\GraphQL\Language\AST\Node|null>|Node|null = null
$source : Source|null = null
$positions : array<int, int>|null = null
$path : array<int, int|string>|null = null
$previous : Throwable|null = null
$extensions : array<string, mixed>|null = null
$unaliasedPath : array<int, int|string>|null = null
Return values
mixed

createLocatedError()

Given an arbitrary Error, presumably thrown while attempting to execute a Automattic\WooCommerce\Vendor\GraphQL operation, produce a new GraphQLError aware of the location in the document responsible for the original Error.

public static createLocatedError(mixed $error[, iteratable<string|int, Node>|Node|null $nodes = null ][, array<int, int|string>|null $path = null ][, array<int, int|string>|null $unaliasedPath = null ]) : Error
Parameters
$error : mixed
$nodes : iteratable<string|int, Node>|Node|null = null
$path : array<int, int|string>|null = null
$unaliasedPath : array<int, int|string>|null = null
Return values
Error

getExtensions()

Data to include within the "extensions" key of the formatted error.

public getExtensions() : array<string, mixed>|null
Return values
array<string, mixed>|null

getLocations()

An array of locations within the source Automattic\WooCommerce\Vendor\GraphQL document which correspond to this error.

public getLocations() : array<int, SourceLocation>

Each entry has information about line and column within source Automattic\WooCommerce\Vendor\GraphQL document: $location->line; $location->column;

Errors during validation often contain multiple locations, for example to point out to field mentioned in multiple fragments. Errors during execution include a single location, the field which produced the error.

Return values
array<int, SourceLocation>

getPath()

Returns an array describing the path from the root value to the field which produced this error.

public getPath() : array<int, int|string>|null

Only included for execution errors. When fields are aliased, the path includes aliases.

Return values
array<int, int|string>|null

getUnaliasedPath()

Returns an array describing the path from the root value to the field which produced this error.

public getUnaliasedPath() : array<int, int|string>|null

Only included for execution errors. This will never include aliases.

Return values
array<int, int|string>|null