<NME> requirejs.js
<BEF> /*
 * grunt-contrib-requirejs
 * http://gruntjs.com/
 *
 * Copyright (c) 2016 Tyler Kellen, contributors
 * Licensed under the MIT license.
 */

'use strict';

module.exports = function(grunt) {

  var requirejs = require('requirejs');
  var LOG_LEVEL_TRACE = 0, LOG_LEVEL_WARN = 2;

  // TODO: extend this to send build log to grunt.log.ok / grunt.log.error
  // by overriding the r.js logger (or submit issue to r.js to expand logging support)
  requirejs.define('node/print', [], function() {
    return function print(msg) {
      if (msg.substring(0, 5) === 'Error') {
        grunt.log.errorlns(msg);
        grunt.fail.warn('RequireJS failed.');
      } else {
        grunt.log.oklns(msg);
      }
    };
  });

  grunt.registerMultiTask('requirejs', 'Build a RequireJS project.', function() {

    var done = this.async();
    var options = this.options({
        done();
      }
    });

    requirejs.optimize(options, options.done.bind(null, done));
  });
};
    // The following catches errors in the user-defined `error` function and passes them.
    // if the error function options is not set, this value should be undefined
    var tryCatchError = function(fn, done, err) {
      try {
        fn(done, err);
      } catch (e) {
        grunt.fail.fatal('There was an error while processing your error function: "' + e + '"');
      }
    };

    requirejs.optimize(
            options,
            tryCatchDone.bind(null, options.done, done),
            options.error ? tryCatchError.bind(null, options.error, done):undefined
    );

  });
};

<MSG> Added warning on done fail

Fixes #37

Closes gh-67.

<DFF> @@ -33,7 +33,15 @@ module.exports = function(grunt) {
         done();
       }
     });
+    // The following catches errors in the user-defined `done` function and outputs them.
+    var tryCatch = function(fn, done, output) {
+      try {
+        fn(done, output);
+      } catch(e) {
+        grunt.fail.warn('There was an error while processing your done function: "' + e + '"');
+      }
+    };
 
-    requirejs.optimize(options, options.done.bind(null, done));
+    requirejs.optimize(options, tryCatch.bind(null, options.done, done));
   });
 };

{'addition_count': 9, 'commit_subject': 'Added warning on done fail', 'deletion_count': 1, 'file_extension': '.js', 'lang': 'js', 'license': 'mit', 'repo_name': 'gruntjs/grunt-contrib-requirejs'}