Skip to content

Commit

Permalink
fix(jsii-diff): catch exception if type disappeared from other assemb…
Browse files Browse the repository at this point in the history
…ly (#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.
  • Loading branch information
rix0rrr authored and RomainMuller committed May 21, 2019
1 parent d1d0633 commit 8d11900
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/jsii-diff/lib/type-analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8d11900

Please sign in to comment.