Skip to content

Commit

Permalink
Catch error if file content could not be parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Frömer committed Feb 6, 2022
1 parent 037ed84 commit 57b2ab8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased] - TBA
### Fixed
- Fixed `FileContentProvider` to throw an exception when the file does not exist
- Added `try/catch` to `FileSymbolProvider` to continue working instead of crashing if a file could not be parsed
### Added
### Changed
### Removed
Expand Down
5 changes: 5 additions & 0 deletions src/Exception/IOException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ public static function unableToOpenHandle(string $path): self
{
return new self('Unable to open resource ' . $path);
}

public static function fileDoesNotExist(string $path): self
{
return new self('File does not exist: ' . $path);
}
}
2 changes: 1 addition & 1 deletion src/Parser/PHP/AbstractCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

abstract class AbstractCollector extends NodeVisitorAbstract implements SymbolCollectorInterface
{
private ?Closure $includeCallback;
private ?Closure $includeCallback = null;

public function setFileIncludeCallback(Closure $includeCallback): void
{
Expand Down
15 changes: 10 additions & 5 deletions src/Symbol/Provider/FileSymbolProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ public function __construct(SymbolNameParserInterface $parser, FileContentProvid
public function provide(): Generator
{
foreach ($this->fileIterator as $file) {
$content = $this->fileContentProvider->getContent($file);
$this->parser->setCurrentFile($file);

foreach ($this->parser->parseSymbolNames($content) as $symbolName) {
yield $symbolName => new Symbol($symbolName);
try {
$content = $this->fileContentProvider->getContent($file);
$this->parser->setCurrentFile($file);

foreach ($this->parser->parseSymbolNames($content) as $symbolName) {
yield $symbolName => new Symbol($symbolName);
}
} catch (IOException $exception) {
// TODO add logging
continue;
}
}

Expand Down

0 comments on commit 57b2ab8

Please sign in to comment.