Skip to content

Commit

Permalink
Handle FS error when profiler files are read
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Apr 16, 2024
1 parent ab2cc53 commit a276d29
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Info
{
public const NAME = 'Buggregator Trap';
public const VERSION = '1.4.6';
public const VERSION = '1.4.7';
public const LOGO_CLI_COLOR = <<<CONSOLE
\e[44;97;1m \e[0m
\e[44;97;1m ▄█▀ ▀█▄ \e[0m
Expand Down
2 changes: 1 addition & 1 deletion src/Service/FilesObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(
) {
foreach ($configs as $config) {
$this->fibers[] = new Fiber(function () use ($config) {
foreach (Handler::generate($config) as $frame) {
foreach (Handler::generate($config, $this->logger) as $frame) {
$this->propagateFrame($frame);
}
});
Expand Down
1 change: 1 addition & 0 deletions src/Service/FilesObserver/Filter/XHProf.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function convert(FileInfo $file): \Traversable
'filename' => $file->getName(),
];

/** @psalm-suppress MixedArgumentTypeCoercion */
yield new ProfilerFrame(
ProfilerFrame\Payload::new(
type: ProfilerFrame\Type::XHProf,
Expand Down
28 changes: 18 additions & 10 deletions src/Service/FilesObserver/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Buggregator\Trap\Service\FilesObserver;

use Buggregator\Trap\Config\FilesObserver as Config;
use Buggregator\Trap\Logger;
use Buggregator\Trap\Proto\Frame;
use Buggregator\Trap\Support\Timer;

Expand All @@ -21,6 +22,7 @@ final class Handler

private function __construct(
Config $config,
private readonly Logger $logger,
) {
$this->path = $config->path;
$this->timer = new Timer($config->interval);
Expand All @@ -30,9 +32,9 @@ private function __construct(
/**
* @return \Generator<int, Frame, mixed, void>
*/
public static function generate(Config $config): \Generator
public static function generate(Config $config, Logger $logger): \Generator
{
$self = new self($config);
$self = new self($config, $logger);
do {
foreach ($self->syncFiles() as $info) {
yield from $self->converter->convert($info);
Expand Down Expand Up @@ -71,16 +73,22 @@ private function syncFiles(): array
*/
private function getFiles(): \Traversable
{
/** @var \Iterator<\SplFileInfo> $iterator */
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($this->path, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::SELF_FIRST,
);
try {
/** @var \Iterator<\SplFileInfo> $iterator */
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($this->path, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::SELF_FIRST,
);

foreach ($iterator as $fileInfo) {
if ($fileInfo->isFile() && $this->converter->validate($info = FileInfo::fromSplFileInfo($fileInfo))) {
yield $info;
foreach ($iterator as $fileInfo) {
if ($fileInfo->isFile() && $this->converter->validate($info = FileInfo::fromSplFileInfo($fileInfo))) {
yield $info;
}
}
} catch (\Throwable $e) {
$this->logger->info('Failed to read files from path `%s`', $this->path);
$this->logger->exception($e);
return [];
}
}
}

0 comments on commit a276d29

Please sign in to comment.