<commit_before>const { normalize } = require('./units/normalize');
const { validateMessage } = require('./validateMessage');

function validate(real, expected, type, callback) {
  const normalizedReal = normalize(real);
  const normalizedExpected = normalize(expected);

  if (type !== 'request' && type !== 'response') {
    throw new Error(
      `Can't validate: expected transaction "type" to be "request" or "response", but got: ${type}.`
    );
  }

  try {
    const results = validateMessage(normalizedReal, normalizedExpected);
    callback(null, {
      version: '2',
      ...results
    });
  } catch (error) {
    callback(error, null);
  }
}

module.exports = validate;<commit_msg>refactor: prevents a call to callback within try/catch block<commit_after>const { normalize } = require('./units/normalize');
const { validateMessage } = require('./validateMessage');

function validate(real, expected, type, callback) {
  const normalizedReal = normalize(real);
  const normalizedExpected = normalize(expected);

  if (type !== 'request' && type !== 'response') {
    throw new Error(
      `Can't validate: expected transaction "type" to be "request" or "response", but got: ${type}.`
    );
  }

  let results;

  try {
    results = validateMessage(normalizedReal, normalizedExpected);
  } catch (error) {
    callback(error, null);
    return;
  }

  callback(null, {
    version: '2',
    ...results
  });
}

module.exports = validate;
{'fraction_non_alphanumeric': 0.14738292011019283, 'fraction_numerical': 0.0013774104683195593, 'mean_word_length': 3.7796052631578947, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5730796', 'n_tokens_mistral': 417, 'n_tokens_neox': 401, 'n_words': 115}