<commit_before>import normalizeAjvErrors from 'ajv-error-messages';

function formatValidationErrors(ajvErrors) {
  const normalizedAjvErrors = normalizeAjvErrors(ajvErrors);
  normalizedAjvErrors.fields[''].forEach(requiredMessage => {
    const missingFieldName = requiredMessage.split('\'')[1];

    if(!normalizedAjvErrors.fields[missingFieldName]) {
      normalizedAjvErrors.fields[missingFieldName] = [];
    }
    normalizedAjvErrors.fields[missingFieldName].push('required');
  });

  delete normalizedAjvErrors.fields['']
<commit_msg>Fixed bug where SchemaValidationError would crash if there was an error but no "required" errors<commit_after>import normalizeAjvErrors from 'ajv-error-messages';

function formatValidationErrors(ajvErrors) {
  const normalizedAjvErrors = normalizeAjvErrors(ajvErrors);

  if (normalizedAjvErrors.fields['']) {
    normalizedAjvErrors.fields[''].forEach(requiredMessage => {
      const missingFieldName = requiredMessage.split('\'')[1];

      if(!normalizedAjvErrors.fields[missingFieldName]) {
        normalizedAjvErrors.fields[missingFieldName] = [];
      }
      normalizedAjvErrors.fields[missingFieldName].push('required');
    });

    delete normalizedAjvErrors.fields['']
  }

{'fraction_non_alphanumeric': 0.11931818181818182, 'fraction_numerical': 0.0016233766233766235, 'mean_word_length': 5.664864864864865, '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': '2349572', 'n_tokens_mistral': 364, 'n_tokens_neox': 360, 'n_words': 52}