From 8d11900e1141ec27f025f5bdaebaf1fa5e28dc6c Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Tue, 21 May 2019 11:51:28 +0200 Subject: [PATCH] fix(jsii-diff): catch exception if type disappeared from other assembly (#504) Make jsii-diff not crash in the following case: - Assembly A depends on Assembly B, and they both update simultaneously. - Assembly A' uses a return type T' freshly introduced in Assembly B'. When doing the supertype check, the compatibility check of A -> A', the lookup of T' inside B would lead to an exception, which would crash the tool. --- packages/jsii-diff/lib/type-analysis.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/jsii-diff/lib/type-analysis.ts b/packages/jsii-diff/lib/type-analysis.ts index 37afbd2601..c89ac0522e 100644 --- a/packages/jsii-diff/lib/type-analysis.ts +++ b/packages/jsii-diff/lib/type-analysis.ts @@ -64,10 +64,16 @@ export function isSuperType(a: reflect.TypeReference, b: reflect.TypeReference, // and the NEW type system. // We could do more complex analysis on typing of methods, but it doesn't seem // worth it. - const A = a.type!; // Note: lookup in old type system! - const B = b.type!; - if (A.isInterfaceType() && A.isDataType() && B.isInterfaceType() && B.datatype) { - return isStructuralSuperType(A, B, updatedSystem); + try { + const A = a.type!; // Note: lookup in old type system! + const B = b.type!; + if (A.isInterfaceType() && A.isDataType() && B.isInterfaceType() && B.datatype) { + return isStructuralSuperType(A, B, updatedSystem); + } + } catch (e) { + // We might get an exception if the type is supposed to come from a different + // assembly and the lookup fails. + return { success: false, reasons: [e.message] }; } // All seems good