Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Catch errors in schema generation and collect them #1008

Merged
merged 4 commits into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Schema/ViewHelperFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 22,10 @@ final class ViewHelperFinder
private const FILE_SUFFIX = 'ViewHelper.php';

private ViewHelperMetadataFactory $viewHelperMetadataFactory;
/**
* @var \Throwable[] $lastErrors
*/
private array $lastErrors = [];
brotkrueml marked this conversation as resolved.
Show resolved Hide resolved

public function __construct(?ViewHelperMetadataFactory $viewHelperMetadataFactory = null)
{
Expand All @@ -33,6 37,7 @@ public function __construct(?ViewHelperMetadataFactory $viewHelperMetadataFactor
*/
public function findViewHelpersInComposerProject(ClassLoader $autoloader): array
{
$this->lastErrors = [];
$viewHelpers = [];
foreach ($autoloader->getPrefixesPsr4() as $namespace => $paths) {
foreach ($paths as $path) {
Expand All @@ -42,6 47,14 @@ public function findViewHelpersInComposerProject(ClassLoader $autoloader): array
return $viewHelpers;
}

/**
* @return \Throwable[]
*/
public function getLastErrors(): array
{
return $this->lastErrors;
}

/**
* @return ViewHelperMetadata[]
*/
Expand Down Expand Up @@ -77,6 90,10 @@ private function findViewHelperFilesInPath(string $namespace, string $path): arr
$viewHelpers[] = $this->viewHelperMetadataFactory->createFromViewhelperClass($className);
} catch (\InvalidArgumentException) {
// Just ignore this class
} catch (\Throwable $t) {
// Catch all Throwables to mitigate technical debt of a ViewHelper
// and avoid aborting the whole generation
$this->lastErrors[] = $t;
}
}
return $viewHelpers;
Expand Down