Improve error messages for nested errors
fredemmott opened this issue · comments
Fred Emmott commented
Fred Emmott commented
@sbilstein: incomplete, but here's what it looks like:
<?hh
require('vendor/hh_autoload.php');
use namespace Facebook\TypeAssert;
class Foo {
const type TShape = shape(
'foo' => string,
'bar' => shape(
'baz' => int,
),
);
const type TDict = dict<string, self::TShape>;
public function main(): void {
$shape = shape(
'foo' => 'herp',
'bar' => shape(
'baz' => 'derp',
),
);
$dict = dict['shape' => $shape];
TypeAssert\matches_type_structure(
type_structure(self::class, 'TDict'),
$dict,
);
}
}
(new Foo())->main();
Freds-Mac-Pro:type-assert fred$ hhvm test.php
Fatal error: Uncaught exception 'Facebook\TypeAssert\IncorrectTypeException' with message 'Expected type 'int', got type 'string'
Type trace:
#0 shape[baz]
#1 shape[bar]
#2 dict<_, Tv>
' in /Users/fred/code/type-assert/src/IncorrectTypeException.php:41
Stack trace:
#0 /Users/fred/code/type-assert/src/IncorrectTypeException.php(53): Facebook\TypeAssert\IncorrectTypeException::withType()
#1 /Users/fred/code/type-assert/src/__Private/IntSpec.php(34): Facebook\TypeAssert\IncorrectTypeException::withValue()
#2 /Users/fred/code/type-assert/src/__Private/ShapeSpec.php(78): Facebook\TypeSpec\__Private\IntSpec->assertType()
#3 /Users/fred/code/type-assert/src/__Private/ShapeSpec.php(78): Facebook\TypeSpec\__Private\ShapeSpec->assertType()
#4 /Users/fred/code/type-assert/src/__Private/DictSpec.php(61): Facebook\TypeSpec\__Private\ShapeSpec->assertType()
#5 /Users/fred/code/type-assert/vendor/hhvm/hsl/src/dict/transform.php(238): Closure$Facebook\TypeSpec\__Private\DictSpec::assertType()
#6 /Users/fred/code/type-assert/src/__Private/DictSpec.php(66): HH\Lib\Dict\pull_with_key()
#7 /Users/fred/code/type-assert/src/TypeAssert.php(63): Facebook\TypeSpec\__Private\DictSpec->assertType()
#8 /Users/fred/code/type-assert/test.php(27): Facebook\TypeAssert\matches_type_structure()
#9 /Users/fred/code/type-assert/test.php(31): Foo->main()
#10 {main}