44
55namespace TypeLang \PHPDoc ;
66
7+ use TypeLang \PHPDoc \Exception \InvalidTagException ;
8+ use TypeLang \PHPDoc \Exception \ParsingException ;
9+ use TypeLang \PHPDoc \Exception \RuntimeExceptionInterface ;
710use TypeLang \PHPDoc \Parser \Description \DescriptionParserInterface ;
811use TypeLang \PHPDoc \Tag \Tag ;
912
@@ -16,7 +19,7 @@ public function __construct(
1619 private array $ factories = [],
1720 ) {}
1821
19- public function add (array |string $ tags , FactoryInterface $ delegate ): void
22+ public function register (array |string $ tags , FactoryInterface $ delegate ): void
2023 {
2124 foreach ((array ) $ tags as $ tag ) {
2225 $ this ->factories [$ tag ] = $ delegate ;
@@ -28,7 +31,24 @@ public function create(string $name, string $content, DescriptionParserInterface
2831 $ delegate = $ this ->factories [$ name ] ?? null ;
2932
3033 if ($ delegate !== null ) {
31- return $ delegate ->create ($ name , $ content , $ descriptions );
34+ try {
35+ return $ delegate ->create ($ name , $ content , $ descriptions );
36+ } catch (ParsingException $ e ) {
37+ throw $ e ;
38+ } catch (RuntimeExceptionInterface $ e ) {
39+ throw InvalidTagException::fromCreatingTag (
40+ tag: $ name ,
41+ source: $ e ->getSource (),
42+ offset: $ e ->getOffset (),
43+ prev: $ e ,
44+ );
45+ } catch (\Throwable $ e ) {
46+ throw InvalidTagException::fromCreatingTag (
47+ tag: $ name ,
48+ source: $ content ,
49+ prev: $ e ,
50+ );
51+ }
3252 }
3353
3454 return new Tag ($ name , $ descriptions ->parse ($ content ));
0 commit comments