Skip to content

Commit 7a09d87

Browse files
committed
Tweak error handling
1 parent ff062a3 commit 7a09d87

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/ClassAttributeCollector.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Composer\IO\IOInterface;
77
use ReflectionAttribute;
88
use ReflectionClass;
9+
use ReflectionException;
910
use Throwable;
1011

1112
/**
@@ -28,16 +29,12 @@ public function __construct(
2829
* }
2930
* Where `0` is an array of class attributes, `1` is an array of method attributes,
3031
* and `2` is an array of property attributes.
32+
*
33+
* @throws ReflectionException
3134
*/
3235
public function collectAttributes(string $class): array
3336
{
34-
try {
35-
$classReflection = new ReflectionClass($class);
36-
} catch (Throwable $e) { // @phpstan-ignore-line
37-
$this->io->error("Unable to collection attribute from class $class: {$e->getMessage()}");
38-
39-
return [ [], [], [] ];
40-
}
37+
$classReflection = new ReflectionClass($class);
4138

4239
if (self::isAttribute($classReflection)) {
4340
return [ [], [], [] ];

src/MemoizeAttributeCollector.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
use Composer\IO\IOInterface;
66
use ReflectionException;
77

8+
use RuntimeException;
9+
use Throwable;
10+
811
use function array_filter;
912
use function filemtime;
1013

@@ -73,11 +76,18 @@ public function collectAttributes(array $classMap): TransientCollection
7376
$this->io->debug("Collect attributes of class '$class' in '$filepath'");
7477
}
7578

76-
[
77-
$classAttributes,
78-
$methodAttributes,
79-
$propertyAttributes
80-
] = $classAttributeCollector->collectAttributes($class);
79+
try {
80+
[
81+
$classAttributes,
82+
$methodAttributes,
83+
$propertyAttributes
84+
] = $classAttributeCollector->collectAttributes($class);
85+
} catch (Throwable $e) {
86+
$this->io->error(
87+
"Attribute collection failed for $class: {$e->getMessage()}"
88+
);
89+
}
90+
8191
$this->state[$class] = [ time(), $classAttributes, $methodAttributes, $propertyAttributes ];
8292
}
8393

0 commit comments

Comments
 (0)