From 77e13e459b321cff1be0935130170761eaa861e6 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Sun, 5 Dec 2010 15:40:49 -0500 Subject: [PATCH] Fixing the repl so that errors print properly, and async exceptions are logged instead of killing the session. --- lib/repl.js | 5 ++++- src/repl.coffee | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) 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> '