Skip to content

Commit

Permalink
repl: fix abruptly exiting on completion errors
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Feb 24, 2022
1 parent 3a0c21e commit eca0e9e
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/js/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,13 @@ window.addEventListener('unhandledrejection', event => {
var buf = new Uint8Array(4096);
var nread;
while (true) {
nread = await tjs.stdin.read(buf);
for(var i = 0; i < nread; i++)
handle_byte(buf[i]);
try {
nread = await tjs.stdin.read(buf);
for(var i = 0; i < nread; i++)
handle_byte(buf[i]);
} catch (error) {
dump_error(error);
}
}
}

Expand Down Expand Up @@ -1008,18 +1012,22 @@ window.addEventListener('unhandledrejection', event => {
/* set the last result */
g._ = result;
} catch (error) {
stdout_write(colors[styles.error_msg]);
if (error instanceof Error) {
stdout_write(error);
stdout_write("\n");
stdout_write(error.stack);
} else {
stdout_write("Throw: ");
stdout_write(error);
}
dump_error(error);
}
}

function dump_error(error) {
stdout_write(colors[styles.error_msg]);
if (error instanceof Error) {
stdout_write(error);
stdout_write("\n");
stdout_write(colors.none);
stdout_write(error.stack);
} else {
stdout_write("Throw: ");
stdout_write(error);
}
stdout_write("\n");
stdout_write(colors.none);
}

function cmd_start() {
Expand Down

0 comments on commit eca0e9e

Please sign in to comment.