[BC broken] Exception type for `DictSpec::assertType()` changed between 3.6.1 and 3.6.2
lexidor opened this issue · comments
In my attempt to allow slackhq/hack-json-schema to run on hhvm 4.27, I found that the newer hhvm versions failed the test suite. After hours of debugging I pinned it down on this concept.
use namespace Facebook\TypeSpec;
use namespace Facebook\TypeAssert;
<<__EntryPoint>>
async function main_async(): Awaitable<void> {
require_once __DIR__.'/vendor/autoload.hack';
Facebook\AutoloadMap\initialize();
try {
$spec = TypeSpec\dict(TypeSpec\string(), TypeSpec\mixed());
$spec->assertType([1, 2, 3, 4]);
} catch (TypeAssert\TypeCoercionException $t) {
echo "You are running TypeAssert 3.6.1\n";
} catch (TypeAssert\IncorrectTypeException $t) {
echo "You are running TypeAssert 3.6.2\n";
}
}
In ObjectConstraint::check()
they catch TypeCoercionException to detect and fallback to an array check instead. This exception is now no longer caught. This caused a handful of test failures.
It appears like this change was made intentionally. I'll rewrite the code in hack-json-schema to work with both exception types.
Commit by @fredemmott
9f0f497
The intent is that TypeCoercionException should never be thrown by assertType, and IncorrectTypeException should never be thrown by coerceType
I have updated the affected code in hack-json-schema. Now it will now work with both exception types. You are right about throwing IncorrectTypeException. It just broke some software out in the wild. Closing.