Skip to content

Commit

Permalink
fix(cli): Show correct error when module traps (#2050)
Browse files Browse the repository at this point in the history
  • Loading branch information
ospencer authored Mar 2, 2024
1 parent 4c3203c commit 88560f2
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cli/bin/grainrun.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ async function run(filename) {
bytes = await readFile(filename);
} catch (err) {
console.error(`Unable to read file: ${filename}`);
process.exit(1);
process.exitCode = 1;
return;
}

let wasm;
Expand All @@ -53,16 +54,26 @@ async function run(filename) {
console.error(`Unable to compile WebAssembly module.`);
console.error(err.stack);
}
process.exit(1);
process.exitCode = 1;
return;
}

let instance;
try {
const instance = await WebAssembly.instantiate(wasm, importObject);
wasi.start(instance);
instance = await WebAssembly.instantiate(wasm, importObject);
} catch (err) {
console.error(`Unable to instantiate WebAssembly module.`);
console.error(err.stack);
process.exit(1);
process.exitCode = 1;
return;
}

try {
wasi.start(instance);
} catch (err) {
console.error(err.stack);
process.exitCode = 1;
return;
}
}

Expand Down

0 comments on commit 88560f2

Please sign in to comment.