<commit_before>/* global ERRORS */

import * as generatedErrors from '../generated-errors/index';
import ChromiumNetError from './ChromiumNetError';

const errors = ERRORS;

const errorCodeMap = {};
errors.forEach((error) => {
  errorCodeMap[error.code] = generatedErrors[error.name];
});

export function getErrors() {
  return [...errors];
}

export function createByCode(code) {
  const Err = errorCodeMap[code];
  if (!Err) { return new ChromiumNetError(); }

  return new Err();
}<commit_msg>Return UnknownError if unknown error code<commit_after>/* global ERRORS */

import * as generatedErrors from '../generated-errors/index';
import ChromiumNetError from './ChromiumNetError';

export class UnknownError extends ChromiumNetError {
  constructor(...args) {
    super(...args);

    this.name = 'UnknownError';
    this.message = 'Unknown error';
  }
}

const errors = ERRORS;

const errorCodeMap = {};
errors.forEach((error) => {
  errorCodeMap[error.code] = generatedErrors[error.name];
});

export function getErrors() {
  return [...errors];
}

export function createByCode(code) {
  const Err = errorCodeMap[code];
  if (!Err) { return new UnknownError(); }

  return new Err();
}
{'fraction_non_alphanumeric': 0.14513422818791946, 'fraction_numerical': 0.0, 'mean_word_length': 4.422727272727273, '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': '295462', 'n_tokens_mistral': 363, 'n_tokens_neox': 353, 'n_words': 95}