From 0941c2da0e058b9972b3e791098b262e0e133e61 Mon Sep 17 00:00:00 2001 From: Daniel Steigerwald Date: Mon, 11 Nov 2013 18:58:57 -0800 Subject: [PATCH] Handle transform errors with nice logging. Try catch to not break Grunt watchers. --- tasks/react.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tasks/react.js b/tasks/react.js index dfe6531..e5ed750 100644 --- a/tasks/react.js +++ b/tasks/react.js @@ -62,10 +62,19 @@ module.exports = function(grunt) { grunt.log.writeln("[react] "+srcFile+" --> "+destFile); - var src = fs.readFileSync(srcFile).toString(); - var newSrc = transform(src); - var destDir = path.dirname(destFile); + var src = fs.readFileSync(srcFile).toString(); + var newSrc; + try { + newSrc = transform(src); + } + catch(e) { + grunt.log.error(e); + grunt.fail.warn('JSX failed to compile.'); + return; + } + + var destDir = path.dirname(destFile); mkdirp.sync(destDir); fs.writeFileSync(destFile, newSrc);