all files / cli/error/ index.js

76.19% Statements 16/21
50% Branches 5/10
100% Functions 1/1
80% Lines 16/20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57    1×   1×   1× 1×                             1×   1×   1× 1×   1×     1×     1×         1×       1×         1×   1×       1×  
'use strict';
 
const appRoot  = require('app-root-path');
 
const Version = require(`${appRoot}/lib/common/version`);
 
const colors  = require('colors');
const _       = require('lodash');
 
/**
 * Class that manage errors of all types.
 */
class Error {
  /**
   * Returns formatted error message
   * @param {string} error - error message
   * @param {boolean} noSqzError - true for system error
   * @returns {String}
   *
   * @name this.sqz.error
   */
  get(errorParam, noSqzError) {
    let error = errorParam;
 
    Iif (_.has(error, 'stack') && noSqzError) error = error.stack;
 
    const versionInfo = new Version();
    let msg           = colors.red.bold('\n\nSQUEEZER ERROR:');
 
    Iif (noSqzError) {
      msg += `\n\n${error}\n\n`;
    } else {
      msg += `\n\n${error}\n\n`;
    }
 
    Iif (noSqzError) {
      msg += `${colors.yellow.bold(versionInfo.msg())}\n\n`;
      msg += `Please add ${colors.green('--debug')} to any command for more CLI details\n\n`;
    }
 
    msg +=
      `### Docs: ${colors.cyan('docs.squeezer.io')}\n` +
      `### Bugs: ${colors.cyan('github.com/SqueezerIO/squeezer/issues')}`;
 
    Iif (noSqzError) {
      msg += `${colors.red('\n\n### If you feel that this error it\'s ' +
        'a bug please report it . Thank you !')}`;
    }
 
    msg += '\n';
 
    return msg;
  }
}
 
module.exports = Error;