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

feat(cli): Improve error handling around grain run #1913

Merged
merged 6 commits into from
Oct 9, 2023
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 WASM module.`);
ospencer marked this conversation as resolved.
Show resolved Hide resolved
console.error(err.statck);
}
process.exit(1);
}

try {
const instance = await WebAssembly.instantiate(wasm, importObject);
wasi.start(instance);
} catch (err) {
console.error(`Unable to instantiate WASM module.`);
ospencer marked this conversation as resolved.
Show resolved Hide resolved
console.error(err.stack);
process.exit(1);
}
Expand Down
Loading