Skip to content

Commit ddea764

Browse files
authored
Merge pull request #84 from OwlyCode/php7-errors-handling
Added compatibility with php7 error handling
2 parents 5be0944 + d022b19 commit ddea764

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Error/Error.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public static function createLocatedError($error, $nodes = null, $path = null)
8989
} else if ($error instanceof \Exception) {
9090
$message = $error->getMessage();
9191
$originalError = $error;
92+
} else if ($error instanceof \Error) {
93+
$message = $error->getMessage();
94+
$originalError = $error;
9295
} else {
9396
$message = (string) $error;
9497
}
@@ -119,9 +122,9 @@ public static function formatError(Error $error)
119122
* @param Source $source
120123
* @param array|null $positions
121124
* @param array|null $path
122-
* @param \Exception $previous
125+
* @param \Exception|\Error $previous
123126
*/
124-
public function __construct($message, $nodes = null, Source $source = null, $positions = null, $path = null, \Exception $previous = null)
127+
public function __construct($message, $nodes = null, Source $source = null, $positions = null, $path = null, $previous = null)
125128
{
126129
parent::__construct($message, 0, $previous);
127130

src/Executor/Executor.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,8 @@ private function resolveOrError($fieldDef, $fieldNode, $resolveFn, $source, $con
680680
return $resolveFn($source, $args, $context, $info);
681681
} catch (\Exception $error) {
682682
return $error;
683+
} catch (\Error $error) {
684+
return $error;
683685
}
684686
}
685687

@@ -778,6 +780,8 @@ public function completeValueWithLocatedError(
778780
return $completed;
779781
} catch (\Exception $error) {
780782
throw Error::createLocatedError($error, $fieldNodes, $path);
783+
} catch (\Error $error) {
784+
throw Error::createLocatedError($error, $fieldNodes, $path);
781785
}
782786
}
783787

@@ -810,6 +814,7 @@ public function completeValueWithLocatedError(
810814
* @return array|null|Promise
811815
* @throws Error
812816
* @throws \Exception
817+
* @throws \Error
813818
*/
814819
private function completeValue(
815820
Type $returnType,
@@ -835,6 +840,10 @@ private function completeValue(
835840
throw $result;
836841
}
837842

843+
if ($result instanceof \Error) {
844+
throw $result;
845+
}
846+
838847
// If field type is NonNull, complete for inner type, and throw field error
839848
// if result is null.
840849
if ($returnType instanceof NonNull) {

0 commit comments

Comments
 (0)