summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorandy finch <andyfinch7@gmail.com>2019-04-04 05:33:32 -0400
committerRyan Dahl <ry@tinyclouds.org>2019-04-04 05:33:32 -0400
commit0e7311e1717edd312d371148f331fb558d9bcc4b (patch)
tree38957fde88f8359886f4f7a00bea91668c7609b3 /js
parent8c8576619852ee8b8095ca735f6d517a7e707e79 (diff)
Non-fatal compile_sync failures (#2039)
And model worker resources as Stream
Diffstat (limited to 'js')
-rw-r--r--js/compiler.ts22
1 files changed, 17 insertions, 5 deletions
diff --git a/js/compiler.ts b/js/compiler.ts
index 72ac391ea..6172b614f 100644
--- a/js/compiler.ts
+++ b/js/compiler.ts
@@ -47,6 +47,7 @@ interface CompilerLookup {
specifier: ModuleSpecifier;
referrer: ContainingFile;
isWorker: boolean;
+ cmdId: number;
}
/** Abstraction of the APIs required from the `os` module so they can be
@@ -522,11 +523,22 @@ window.TextEncoder = TextEncoder;
window.compilerMain = function compilerMain() {
// workerMain should have already been called since a compiler is a worker.
window.onmessage = ({ data }: { data: CompilerLookup }) => {
- const { specifier, referrer } = data;
-
- const result = compiler.compile(specifier, referrer);
-
- postMessage(result);
+ const { specifier, referrer, cmdId } = data;
+
+ try {
+ const result = compiler.compile(specifier, referrer);
+ postMessage({
+ success: true,
+ cmdId,
+ data: result
+ });
+ } catch (e) {
+ postMessage({
+ success: false,
+ cmdId,
+ data: JSON.parse(core.errorToJSON(e))
+ });
+ }
};
};