'use strict';

module.exports = function (err, data) {

  if (err) {
    return 'Debug output: %j' + JSON.stringify(data) + '\n' + JSON.stringify(err);
  }

  if (!data.length) {
    return;
  }

  var returnString = '';
  for (var i = 0, il = data.length; i < il; ++i) {
    returnString += JSON.stringify({
      type: 'issue',
      check_name: 'Vulnerable module "' + data[i].module + '" identified',
      description: '`' + data[i].module + '` ' + data[i].title,
      categories: ['Security'],
      remediation_points: 300000,
      content: {
        body: data[i].content
      },
      location: {
        path: 'npm-shrinkwrap.json',
        lines: {
          begin: data[i].line.start,
          end: data[i].line.end
        }
      }
    }) + '\0\n';
  }

  return returnString;
};

'use strict';

module.exports = function (err, data) {

  if (err) {
    return err.stack;
  }

  if (!data.length) {
    return;
  }

  var returnString = '';
  for (var i = 0, il = data.length; i < il; ++i) {
    returnString += JSON.stringify({
      type: 'issue',
      check_name: 'Vulnerable module "' + data[i].module + '" identified',
      description: '`' + data[i].module + '` ' + data[i].title,
      categories: ['Security'],
      remediation_points: 300000,
      content: {
        body: data[i].content
      },
      location: {
        path: 'npm-shrinkwrap.json',
        lines: {
          begin: data[i].line.start,
          end: data[i].line.end
        }
      }
    }) + '\0\n';
  }

  return returnString;
};

Return error message in Code Climate runs
Return error message in Code Climate runs

Stringifying an Error object results in {} so the formatter was not
returning the actual underlying error with the Code Climate formatter.
This change returns the error so that they user can take action if an
analysis run fails.

This change returns the Error stack which includes a helpful error
message and the backtrace for debugging purposes.
