3 var grunt = require('../grunt');
5 // The module to be exported.
6 var fail = module.exports = {};
14 INVALID_AUTOCOMPLETE: 5,
19 function writeln(e, mode) {
20 grunt.log.muted = false;
21 var msg = String(e.message || e);
22 if (!grunt.option('no-color')) { msg += '\x07'; } // Beep!
23 if (mode === 'warn') {
24 msg = 'Warning: ' + msg + ' ';
25 msg += (grunt.option('force') ? 'Used --force, continuing.'.underline : 'Use --force to continue.');
28 msg = ('Fatal error: ' + msg).red;
30 grunt.log.writeln(msg);
33 // If --stack is enabled, log the appropriate error stack (if it exists).
34 function dumpStack(e) {
35 if (grunt.option('stack')) {
36 if (e.origError && e.origError.stack) {
37 console.log(e.origError.stack);
44 // A fatal error occurred. Abort immediately.
45 fail.fatal = function(e, errcode) {
48 grunt.util.exit(typeof errcode === 'number' ? errcode : fail.code.FATAL_ERROR);
51 // Keep track of error and warning counts.
55 // A warning occurred. Abort immediately unless -f or --force was used.
56 fail.warn = function(e, errcode) {
57 var message = typeof e === 'string' ? e : e.message;
59 writeln(message, 'warn');
60 // If -f or --force aren't used, stop script processing.
61 if (!grunt.option('force')) {
63 grunt.log.writeln().fail('Aborted due to warnings.');
64 grunt.util.exit(typeof errcode === 'number' ? errcode : fail.code.WARNING);
68 // This gets called at the very end.
69 fail.report = function() {
70 if (fail.warncount > 0) {
71 grunt.log.writeln().fail('Done, but with warnings.');
73 grunt.log.writeln().success('Done.');