From f405f072f2a385222a4a153b3219647d45ad9d7a Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 29 Jun 2011 21:39:50 -0400 Subject: [PATCH] Added 'dismiss' warning handler - Phew. That was a hard one. --- lib/warn.js | 19 +++++++++++++++++++ test/test-warn-handlers.js | 22 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/lib/warn.js b/lib/warn.js index 9a4116b..bb670ef 100644 --- a/lib/warn.js +++ b/lib/warn.js @@ -107,5 +107,24 @@ exports.handlers = { { throw warning.getError(); }, + + + /** + * Ignores warnings + * + * This is useful in a production environment where (a) warnings will affect + * the reputation of the software or (b) warnings may provide too much + * insight into the software. If using this option, you should always + * develop in a separate environment so that the system may bring warnings + * to your attention. + * + * @param {Warning} warning to log + * + * @return {undefined} + */ + dismiss: function( warning ) + { + // do nothing + }, }; diff --git a/test/test-warn-handlers.js b/test/test-warn-handlers.js index 8d509b5..e729cba 100644 --- a/test/test-warn-handlers.js +++ b/test/test-warn-handlers.js @@ -138,3 +138,25 @@ var common = require( './common' ), assert.fail( "Wrapped exception should be thrown" ); } )(); + +/** + * The 'dismiss' error handler is a pretty basic concept. Simply do nothing. We + * don't want to log, we don't want to throw anything, we just want to pretend + * nothing ever happened and move on our merry way. This is intended for use in + * production environments where providing warnings may provide too much insight + * into the software. + */ +( function testDismissWarningHandlerShouldDoNothing() +{ + // destroy the console to ensure nothing is logged + var console_ = console; + console = undefined; + + // don't catch anything, to ensure no errors occur and that no exceptions + // are thrown + warn.handlers.dismiss( warning ); + + // restore console + console = console_; +} )(); +