<commit_before>'use strict';

const { omitBy } = require('../utilities');

const { getReason, getGenericProps } = require('./reasons');
const { normalizeError } = require('./main');

// Gets normalized error information
const getStandardError = function ({ error, mInput, isLimited }) {
  if (!error) { return; }

  const errorA = normalizeError({ error });

  const errorB = fillError({ error: errorA, mInput, isLimited });

  // Do not expose undefined values
  const errorC = omitBy(errorB, val => val === undefined);

  return errorC;
};

// Order matters, as this will be kept in final output
const fillError = function ({
  error,
  mInput: {
    url: instance,
    status = 'SERVER_ERROR',
    protocolstatus,
    protocol,
    method,
    requestheaders,
    queryvars,
    operation,
    summary,
    topArgs: args,
    commandpath,
    modelName: model,
    command,
    requestid,
  } = {},
  isLimited = true,
}) {
  const type = getReason({ error });
  const { title } = getGenericProps({ error });

  const {
    message: description,
    stack: outerStack,
    innererror: { stack: details = outerStack } = {},
    extra = {},
  } = error;

  const errorA = { type, title, description, instance, status };

  if (isLimited) {
    return { ...errorA, ...extra, details };
  }

  return {
    ...errorA,
    protocolstatus: protocolstatus,
    protocol,
    method,
    requestheaders: requestheaders,
    queryvars,
    operation,
    summary,
    args,
    commandpath: commandpath,
    model,
    command,
    requestid: requestid,
    ...extra,
    // Stack trace is not included in error responses, whether in production
    // or in development because:
    //  - it might leak user-supplied code structure (e.g. event payload
    //    handlers)
    //  - it is already present in exception thrown, console event messages and
    //    failure event payload
  };
};

module.exports = {
  getStandardError,
};<commit_msg>Fix linting<commit_after>'use strict';

const { omitBy } = require('../utilities');

const { getReason, getGenericProps } = require('./reasons');
const { normalizeError } = require('./main');

// Gets normalized error information
const getStandardError = function ({ error, mInput, isLimited }) {
  if (!error) { return; }

  const errorA = normalizeError({ error });

  const errorB = fillError({ error: errorA, mInput, isLimited });

  // Do not expose undefined values
  const errorC = omitBy(errorB, val => val === undefined);

  return errorC;
};

// Order matters, as this will be kept in final output
const fillError = function ({
  error,
  mInput: {
    url: instance,
    status = 'SERVER_ERROR',
    protocolstatus,
    protocol,
    method,
    requestheaders,
    queryvars,
    operation,
    summary,
    topArgs: args,
    commandpath,
    modelName: model,
    command,
    requestid,
  } = {},
  isLimited = true,
}) {
  const type = getReason({ error });
  const { title } = getGenericProps({ error });

  const {
    message: description,
    stack: outerStack,
    innererror: { stack: details = outerStack } = {},
    extra = {},
  } = error;

  const errorA = { type, title, description, instance, status };

  if (isLimited) {
    return { ...errorA, ...extra, details };
  }

  return {
    ...errorA,
    protocolstatus,
    protocol,
    method,
    requestheaders,
    queryvars,
    operation,
    summary,
    args,
    commandpath,
    model,
    command,
    requestid,
    ...extra,
    // Stack trace is not included in error responses, whether in production
    // or in development because:
    //  - it might leak user-supplied code structure (e.g. event payload
    //    handlers)
    //  - it is already present in exception thrown, console event messages and
    //    failure event payload
  };
};

module.exports = {
  getStandardError,
};
{'fraction_non_alphanumeric': 0.12349555206698064, 'fraction_numerical': 0.0, 'mean_word_length': 2.7702169625246547, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '315753', 'n_tokens_mistral': 1132, 'n_tokens_neox': 1111, 'n_words': 349}