Skip to content

Commit c90dcdd

Browse files
committed
Pass trace metadata with more non-ignorable exception errors
1 parent f56840c commit c90dcdd

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

src/Analyser/AnalyserResultFinalizer.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,20 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles): Final
5454
]);
5555
continue;
5656
} catch (IdentifierNotFound $e) {
57-
$tempCollectorErrors[] = (new Error(sprintf('Reflection error: %s not found.', $e->getIdentifier()->getName()), $file, $node->getStartLine(), $e, null, null, 'Learn more at https://phpstan.org/user-guide/discovering-symbols'))->withIdentifier('phpstan.reflection');
57+
$tempCollectorErrors[] = (new Error(sprintf('Reflection error: %s not found.', $e->getIdentifier()->getName()), $file, $node->getStartLine(), $e, null, null, 'Learn more at https://phpstan.org/user-guide/discovering-symbols'))
58+
->withIdentifier('phpstan.reflection')
59+
->withMetadata([
60+
InternalError::STACK_TRACE_METADATA_KEY => InternalError::prepareTrace($e),
61+
InternalError::STACK_TRACE_AS_STRING_METADATA_KEY => $e->getTraceAsString(),
62+
]);
5863
continue;
5964
} catch (UnableToCompileNode | CircularReference $e) {
60-
$tempCollectorErrors[] = (new Error(sprintf('Reflection error: %s', $e->getMessage()), $file, $node->getStartLine(), $e))->withIdentifier('phpstan.reflection');
65+
$tempCollectorErrors[] = (new Error(sprintf('Reflection error: %s', $e->getMessage()), $file, $node->getStartLine(), $e))
66+
->withIdentifier('phpstan.reflection')
67+
->withMetadata([
68+
InternalError::STACK_TRACE_METADATA_KEY => InternalError::prepareTrace($e),
69+
InternalError::STACK_TRACE_AS_STRING_METADATA_KEY => $e->getTraceAsString(),
70+
]);
6171
continue;
6272
}
6373

src/Analyser/FileAnalyser.php

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,20 @@ public function analyseFile(
123123
]);
124124
continue;
125125
} catch (IdentifierNotFound $e) {
126-
$fileErrors[] = (new Error(sprintf('Reflection error: %s not found.', $e->getIdentifier()->getName()), $file, $node->getStartLine(), $e, null, null, 'Learn more at https://phpstan.org/user-guide/discovering-symbols'))->withIdentifier('phpstan.reflection');
126+
$fileErrors[] = (new Error(sprintf('Reflection error: %s not found.', $e->getIdentifier()->getName()), $file, $node->getStartLine(), $e, null, null, 'Learn more at https://phpstan.org/user-guide/discovering-symbols'))
127+
->withIdentifier('phpstan.reflection')
128+
->withMetadata([
129+
InternalError::STACK_TRACE_METADATA_KEY => InternalError::prepareTrace($e),
130+
InternalError::STACK_TRACE_AS_STRING_METADATA_KEY => $e->getTraceAsString(),
131+
]);
127132
continue;
128133
} catch (UnableToCompileNode | CircularReference $e) {
129-
$fileErrors[] = (new Error(sprintf('Reflection error: %s', $e->getMessage()), $file, $node->getStartLine(), $e))->withIdentifier('phpstan.reflection');
134+
$fileErrors[] = (new Error(sprintf('Reflection error: %s', $e->getMessage()), $file, $node->getStartLine(), $e))
135+
->withIdentifier('phpstan.reflection')
136+
->withMetadata([
137+
InternalError::STACK_TRACE_METADATA_KEY => InternalError::prepareTrace($e),
138+
InternalError::STACK_TRACE_AS_STRING_METADATA_KEY => $e->getTraceAsString(),
139+
]);
130140
continue;
131141
}
132142

@@ -152,10 +162,20 @@ public function analyseFile(
152162
]);
153163
continue;
154164
} catch (IdentifierNotFound $e) {
155-
$fileErrors[] = (new Error(sprintf('Reflection error: %s not found.', $e->getIdentifier()->getName()), $file, $node->getStartLine(), $e, null, null, 'Learn more at https://phpstan.org/user-guide/discovering-symbols'))->withIdentifier('phpstan.reflection');
165+
$fileErrors[] = (new Error(sprintf('Reflection error: %s not found.', $e->getIdentifier()->getName()), $file, $node->getStartLine(), $e, null, null, 'Learn more at https://phpstan.org/user-guide/discovering-symbols'))
166+
->withIdentifier('phpstan.reflection')
167+
->withMetadata([
168+
InternalError::STACK_TRACE_METADATA_KEY => InternalError::prepareTrace($e),
169+
InternalError::STACK_TRACE_AS_STRING_METADATA_KEY => $e->getTraceAsString(),
170+
]);
156171
continue;
157172
} catch (UnableToCompileNode | CircularReference $e) {
158-
$fileErrors[] = (new Error(sprintf('Reflection error: %s', $e->getMessage()), $file, $node->getStartLine(), $e))->withIdentifier('phpstan.reflection');
173+
$fileErrors[] = (new Error(sprintf('Reflection error: %s', $e->getMessage()), $file, $node->getStartLine(), $e))
174+
->withIdentifier('phpstan.reflection')
175+
->withMetadata([
176+
InternalError::STACK_TRACE_METADATA_KEY => InternalError::prepareTrace($e),
177+
InternalError::STACK_TRACE_AS_STRING_METADATA_KEY => $e->getTraceAsString(),
178+
]);
159179
continue;
160180
}
161181

@@ -222,9 +242,19 @@ public function analyseFile(
222242
InternalError::STACK_TRACE_AS_STRING_METADATA_KEY => $e->getTraceAsString(),
223243
]);
224244
} catch (IdentifierNotFound $e) {
225-
$fileErrors[] = (new Error(sprintf('Reflection error: %s not found.', $e->getIdentifier()->getName()), $file, null, $e, null, null, 'Learn more at https://phpstan.org/user-guide/discovering-symbols'))->withIdentifier('phpstan.reflection');
245+
$fileErrors[] = (new Error(sprintf('Reflection error: %s not found.', $e->getIdentifier()->getName()), $file, null, $e, null, null, 'Learn more at https://phpstan.org/user-guide/discovering-symbols'))
246+
->withIdentifier('phpstan.reflection')
247+
->withMetadata([
248+
InternalError::STACK_TRACE_METADATA_KEY => InternalError::prepareTrace($e),
249+
InternalError::STACK_TRACE_AS_STRING_METADATA_KEY => $e->getTraceAsString(),
250+
]);
226251
} catch (UnableToCompileNode | CircularReference $e) {
227-
$fileErrors[] = (new Error(sprintf('Reflection error: %s', $e->getMessage()), $file, null, $e))->withIdentifier('phpstan.reflection');
252+
$fileErrors[] = (new Error(sprintf('Reflection error: %s', $e->getMessage()), $file, null, $e))
253+
->withIdentifier('phpstan.reflection')
254+
->withMetadata([
255+
InternalError::STACK_TRACE_METADATA_KEY => InternalError::prepareTrace($e),
256+
InternalError::STACK_TRACE_AS_STRING_METADATA_KEY => $e->getTraceAsString(),
257+
]);
228258
}
229259
} elseif (is_dir($file)) {
230260
$fileErrors[] = (new Error(sprintf('File %s is a directory.', $file), $file, null, false))->withIdentifier('phpstan.path');

0 commit comments

Comments
 (0)