<commit_before>const { EOL } = require('os');
const stripAnsi = require('strip-ansi');

function serializeError(error, _type = undefined) {
  return {
    _type,
    name: error.name,
    message: error.message,
    stack: error.stack,
  };
}

exports.serializeError = serializeError;

function deserializeError(data) {
  if (!data || typeof data !== 'object') {
    return new Error(String(error));
  }

  const { _type, ...error } = data;

  if (_type === 'BuildError') {
    return new BuildError(error);
  } else if (_type === 'CompileError') {
    return new CompilerError(error);
  } else {
    return Object.assign(new Error(error.message), error);
  }
}

exports.deserializeError = deserializeError;<commit_msg>refactor: use switch statement<commit_after>const { EOL } = require('os');
const stripAnsi = require('strip-ansi');

function serializeError(error, _type) {
  return {
    _type,
    name: error.name,
    message: error.message,
    stack: error.stack,
  };
}

exports.serializeError = serializeError;

function deserializeError(data) {
  if (!data || typeof data !== 'object') {
    return new Error(String(error));
  }

  const { _type, ...error } = data;

  switch (_type) {
    case 'BuildError':
      return new BuildError(error);
    case 'CompileError':
      return new CompilerError(error);
    default:
      return Object.assign(new Error(error.message), error);
  }
}

exports.deserializeError = deserializeError;
{'fraction_non_alphanumeric': 0.14048442906574393, 'fraction_numerical': 0.0, 'mean_word_length': 3.740983606557377, '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': '2871140', 'n_tokens_mistral': 454, 'n_tokens_neox': 448, 'n_words': 108}