Skip to content

Commit

Permalink
feat(cli): Improve error handling around grain run (#1913)
Browse files Browse the repository at this point in the history
Co-authored-by: Blaine Bublitz <[email protected]>
Co-authored-by: Oscar Spencer <[email protected]>
  • Loading branch information
3 people authored Oct 9, 2023
1 parent bb59bf9 commit fc9b434
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions cli/bin/grainrun.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,37 @@ const wasi = new WASI({
const importObject = { wasi_snapshot_preview1: wasi.wasiImport };

async function run(filename) {
let bytes;
try {
const wasm = await WebAssembly.compile(await readFile(filename));
const instance = await WebAssembly.instantiate(wasm, importObject);
bytes = await readFile(filename);
} catch (err) {
console.error(`Unable to read file: ${filename}`);
process.exit(1);
}

let wasm;
try {
wasm = await WebAssembly.compile(bytes);
} catch (err) {
if (filename.endsWith(".gr")) {
console.error(
`The \`grain run\` command is used on compiled \`.wasm\` files.`
);
console.error(
`To compile and run your \`.gr\` file, use \`grain ${filename}\``
);
} else {
console.error(`Unable to compile WebAssembly module.`);
console.error(err.statck);

This comment has been minimized.

Copy link
@av8ta

av8ta Oct 12, 2023

Contributor

err.statck is this a typo?

This comment has been minimized.

Copy link
@phated

phated Oct 15, 2023

Author Member

Thanks for catching this!

}
process.exit(1);
}

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

0 comments on commit fc9b434

Please sign in to comment.