From bdd7df20112fe5660ec5a59017615473e5eaa7a3 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 29 Jun 2011 21:34:33 -0400 Subject: [PATCH] Added throwError warning handler --- lib/warn.js | 16 ++++++++++++++++ test/test-warn-handlers.js | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/lib/warn.js b/lib/warn.js index 03409f2..9a4116b 100644 --- a/lib/warn.js +++ b/lib/warn.js @@ -91,5 +91,21 @@ exports.handlers = { console && ( dest = console.warn || console.log ) && dest( warning.message ); }, + + + /** + * Throws the error associated with the warning + * + * This handler is useful for development and will ensure that problems are + * brought to the attention of the developer. + * + * @param {Warning} warning to log + * + * @return {undefined} + */ + throwError: function( warning ) + { + throw warning.getError(); + }, }; diff --git a/test/test-warn-handlers.js b/test/test-warn-handlers.js index 66d7a6e..8d509b5 100644 --- a/test/test-warn-handlers.js +++ b/test/test-warn-handlers.js @@ -116,3 +116,25 @@ var common = require( './common' ), console = console_; } )(); + +/** + * The throwError warning handler should throw the wrapped error as an exception + */ +( function testThrowErrorWarningHandlerThrowsWrappedError() +{ + try + { + warn.handlers.throwError( warning ); + } + catch ( e ) + { + assert.deepEqual( e, warning.getError(), + "Wrapped exception should be thrown" + ); + + return; + } + + assert.fail( "Wrapped exception should be thrown" ); +} )(); +