Skip to content

Commit 8523e23

Browse files
committed
Clear error message
1 parent 32936cc commit 8523e23

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

src/Bridge/ApiPlatform/ApiPlatformInputTypeResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function resolve(SingleType $type, DtoType $dto, DtoList $dtoList): mixed
2727
{
2828
if ($this->isPropertyEnum($type)) {
2929
if (!$dtoList->hasDtoWithType($type->getName())) {
30-
throw UnsupportedTypeException::forType($type);
30+
throw UnsupportedTypeException::forType($type, $dto->getName());
3131
}
3232

3333
return sprintf("{ value: %s }", $type->getName());

src/Language/Dart/DartGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private function handleUnknownType(SingleType $type, DtoType $dto, DtoList $dtoL
132132
}
133133
}
134134

135-
throw UnsupportedTypeException::forType($type);
135+
throw UnsupportedTypeException::forType($type, $dto->getName());
136136
}
137137

138138
/** @param DtoEnumProperty[] $properties */

src/Language/TypeScript/TypeScriptGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,6 @@ private function handleUnknownType(SingleType $type, DtoType $dto, DtoList $dtoL
111111
}
112112
}
113113

114-
throw UnsupportedTypeException::forType($type);
114+
throw UnsupportedTypeException::forType($type, $dto->getName());
115115
}
116116
}

src/Language/UnsupportedTypeException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
class UnsupportedTypeException extends \Exception
1010
{
11-
public static function forType(SingleType $type): self
11+
public static function forType(SingleType $type, string $class): self
1212
{
13-
return new self(sprintf("PHP Type %s is not supported", $type->getName()));
13+
return new self(sprintf("PHP Type %s is not supported. PHP class: %s", $type->getName(), $class));
1414
}
1515
}

tests/EndToEndTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,4 +542,33 @@ class UserCreateInput
542542
$this->assertCount(1, $results);
543543
$this->assertMatchesSnapshot($results[0]->getContent(), new TypeScriptSnapshotComparator());
544544
}
545+
546+
public function testUnkownTypeThrows(): void
547+
{
548+
$codeWithDateTime = <<<'CODE'
549+
<?php
550+
551+
#[\Attribute(\Attribute::TARGET_CLASS)]
552+
class Dto
553+
{
554+
555+
}
556+
557+
#[Dto]
558+
class A
559+
{
560+
public \DateTimeImmutable $createdAt;
561+
public B $b;
562+
}
563+
564+
class B {}
565+
CODE;
566+
567+
$converter = new Converter(Normalizer::factory(new PhpAttributeFilter('Dto')));
568+
$result = $converter->convert([$codeWithDateTime]);
569+
$typeScriptGenerator = new TypeScriptGenerator(new SingleFileOutputWriter('generated.ts'), [new ClassNameTypeResolver(), new DateTimeTypeResolver()]);
570+
571+
$this->expectExceptionMessage('PHP Type B is not supported. PHP class: A');
572+
$results = ($typeScriptGenerator)->generate($result);
573+
}
545574
}

0 commit comments

Comments
 (0)