[playground] Handle invariant violation errors
playground currently hard crashes when we hit an invariant violation <img width="1104" alt="image" src="https://user-images.githubusercontent.com/34200447/214615036-dbe307d8-132d-4186-a8ab-6fcaf69801d1.png"> [playground link](https://0xeac7-forget.vercel.app/#eyJzb3VyY2UiOiJcbmZ1bmN0aW9uIHVzZUJhcihwcm9wcykge1xuICBwcm9wcyA9IG51bGw7XG4gIGxldCB5LCB6O1xuXG4gIGlmIChwcm9wcy54KSB7XG4gICAgbGV0IHkgPSB1c2VGb28ocHJvcHMuYS5iKTtcbiAgICB3aGlsZSAoYmFyKCkpIHtcbiAgICAgIGlmIChwcm9wcy55KSB7XG4gICAgICAgIHogPSBiYXooKTtcbiAgICAgIH1cbiAgICB9XG4gIH1cblxuICByZXR1cm4gW3ksIHpdXG59In0=) This should fix that
mofeiZ committed
Jan 25, 2023 at 11:23 UTC
b00963ffde2e27dea41c311b2b01f7cae5f799be
1 file changed
+5
compiler/forget/packages/playground/components/Editor/index.tsx
+5
@@ -67,6 +67,11 @@ function compile(source: string): CompilerOutput {
67
return { kind: "ok", results };
68
} catch (error: any) {
69
console.error(error);
70
+ // error might be an invariant violation or other runtime error
71
+ // (i.e. object shape that is not CompilerError)
72
+ if (error.details == null) {
73
+ error.details = [];
74
+ }
75
return { kind: "err", error };
76
}
77
}