We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
1 | <?php |
||
15 | class ErrorHandler |
||
16 | { |
||
17 | const DEFAULT_ERROR_MESSAGE = 'Internal server Error'; |
||
18 | |||
19 | /** @var EventDispatcherInterface */ |
||
20 | private $dispatcher; |
||
21 | |||
22 | /** @var string */ |
||
23 | private $internalErrorMessage; |
||
24 | |||
25 | /** @var array */ |
||
26 | private $exceptionMap; |
||
27 | |||
28 | /** @var bool */ |
||
29 | private $mapExceptionsToParent; |
||
30 | |||
31 | 74 | public function __construct( |
|
45 | |||
46 | 73 | public function handleErrors(ExecutionResult $executionResult, $throwRawException = false, $debug = false) |
|
56 | |||
57 | 73 | private function createErrorFormatter($debug = false) |
|
71 | |||
72 | /** |
||
73 | * @param GraphQLError[] $errors |
||
74 | * @param bool $throwRawException |
||
75 | * |
||
76 | * @return array |
||
77 | * |
||
78 | * @throws \Error|\Exception |
||
79 | */ |
||
80 | 73 | private function treatExceptions(array $errors, $throwRawException) |
|
81 | { |
||
82 | $treatedExceptions = [ |
||
83 | 73 | 'errors' => [], |
|
84 | 'extensions' => [ |
||
85 | 'warnings' => [], |
||
86 | ], |
||
87 | ]; |
||
88 | |||
89 | /** @var GraphQLError $error */ |
||
90 | 73 | foreach ($this->flattenErrors($errors) as $error) { |
|
91 | 26 | $rawException = $this->convertException($error->getPrevious()); |
|
92 | |||
93 | // raw GraphQL Error or InvariantViolation exception |
||
94 | 26 | if (null === $rawException) { |
|
95 | 9 | $treatedExceptions['errors'][] = $error; |
|
96 | 9 | continue; |
|
97 | } |
||
98 | |||
99 | // recreate a error with converted exception |
||
100 | 18 | $errorWithConvertedException = new GraphQLError( |
|
101 | 18 | $error->getMessage(), |
|
102 | 18 | $error->nodes, |
|
103 | 18 | $error->getSource(), |
|
104 | 18 | $error->getPositions(), |
|
105 | 18 | $error->path, |
|
106 | 18 | $rawException |
|
107 | ); |
||
108 | |||
109 | // user error |
||
110 | 18 | if ($rawException instanceof GraphQLUserError) { |
|
111 | 8 | $treatedExceptions['errors'][] = $errorWithConvertedException; |
|
112 | 8 | continue; |
|
113 | } |
||
114 | |||
115 | // user warning |
||
116 | 11 | if ($rawException instanceof UserWarning) { |
|
117 | 7 | $treatedExceptions['extensions']['warnings'][] = $errorWithConvertedException; |
|
118 | 7 | continue; |
|
119 | } |
||
120 | |||
121 | // if is a catch exception wrapped in Error |
||
122 | 5 | if ($throwRawException) { |
|
123 | 3 | throw $rawException; |
|
124 | } |
||
125 | |||
126 | 2 | $treatedExceptions['errors'][] = $errorWithConvertedException; |
|
127 | } |
||
128 | |||
129 | 70 | return $treatedExceptions; |
|
130 | } |
||
131 | |||
132 | /** |
||
133 | * @param GraphQLError[] $errors |
||
134 | * |
||
135 | * @return GraphQLError[] |
||
136 | */ |
||
137 | 73 | private function flattenErrors(array $errors) |
|
156 | |||
157 | /** |
||
158 | * Tries to convert a raw exception into a user warning or error |
||
159 | * that is displayed to the user. |
||
160 | * |
||
161 | * @param \Exception|\Error $rawException |
||
162 | * |
||
163 | * @return \Exception|\Error |
||
164 | */ |
||
165 | 26 | private function convertException($rawException = null) |
|
178 | |||
179 | /** |
||
180 | * @param \Exception|\Error $rawException |
||
181 | * |
||
182 | * @return string|null |
||
183 | */ |
||
184 | 13 | private function findErrorClass($rawException) |
|
197 | |||
198 | /** |
||
199 | * @param \Exception|\Error $rawException |
||
200 | * |
||
201 | * @return string|null |
||
202 | */ |
||
203 | 2 | private function findErrorClassUsingParentException($rawException) |
|
213 | } |
||
214 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: