Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Show correct error when module traps #2050

Merged
merged 1 commit into from Mar 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 16 additions & 5 deletions cli/bin/grainrun.js
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