1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-22 08:20:11 +00:00

Scrub error-handler.js.

This commit is contained in:
hacksalot 2016-01-01 14:59:21 -05:00
parent 37a7c318d5
commit 5a2d892b85

View File

@ -1,9 +1,15 @@
/**
Error-handling routines for HackMyResume.
@module error-handler.js
@license MIT. See LICENSE.md for details.
*/
(function() {
var HACKMYSTATUS = require('./status-codes')
, PKG = require('../../package.json')
, FS = require('fs')
@ -12,9 +18,17 @@
, chalk = require('chalk')
, title = chalk.white.bold('\n*** HackMyResume v' + PKG.version + ' ***');
/**
An amorphous blob of error handling code for HackMyResume. Have an error?
Stick it here. We don't mind.
@class ErrorHandler
*/
var ErrorHandler = module.exports = {
err: function( ex, shouldExit ) {
var msg = '', exitCode;
@ -80,8 +94,12 @@
exitCode = 4;
}
// Deal with pesky 'Error:' prefix.
var idx = msg.indexOf('Error: ');
var trimmed = idx === -1 ? msg : msg.substring( idx + 7 );
// If this is an unhandled error, or a specific class of handled error,
// output the error message and stack.
if( !ex.fluenterror || ex.fluenterror < 3 ) { // TODO: magic #s
console.log( chalk.red.bold('ERROR: ' + trimmed.toString()) );
if( ex.code !== 'ENOENT' ) // Don't emit stack for common stuff
@ -91,6 +109,7 @@
console.log( trimmed.toString() );
}
// Let the error code be the process's return code.
if( shouldExit )
process.exit( exitCode );