diff --git a/lib/repl.js b/lib/repl.js index 1e57bb53..044439b9 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -21,10 +21,13 @@ console.log(val); } } catch (err) { - console.error(err.stack || err.toString()); + stdio.write(err.stack || err.toString()); } return repl.prompt(); }; + process.on('uncaughtException', function(err) { + return stdio.write(err.stack || err.toString()); + }); repl = readline.createInterface(stdio); repl.setPrompt('coffee> '); stdio.on('data', function(buffer) { diff --git a/src/repl.coffee b/src/repl.coffee index 78e49f73..d18d4b58 100644 --- a/src/repl.coffee +++ b/src/repl.coffee @@ -23,9 +23,13 @@ run = (buffer) -> val = CoffeeScript.eval buffer.toString(), bare: on, globals: on, fileName: 'repl' console.log val if val isnt undefined catch err - console.error err.stack or err.toString() + stdio.write err.stack or err.toString() repl.prompt() +# Make sure that uncaught exceptions don't kill the REPL. +process.on 'uncaughtException', (err) -> + stdio.write err.stack or err.toString() + # Create the REPL by listening to **stdin**. repl = readline.createInterface stdio repl.setPrompt 'coffee> '