<commit_before>var WSS = require('ws').Server;

function json(name, args) {
  var obj = {
    name: name,
    args: args
  };
  this.send(JSON.stringify(obj));
}

function error(msg) {
  this.json('error', msg);
  this.close();
}

function message(message) {
  message = JSON.parse(message);
  this.emit.apply(this, message);
}

function logError(err) {
  console.log(err);
}

function decorate(ws) {
  ws.json = json;
  ws.error = error;
  ws.on('message', message);
  ws.on('error', logError);
}

function wss(server) {
  var wss = new WSS({ server: server });
  wss.on('connection', decorate);
  return wss;
}

module.exports = wss;<commit_msg>try / catch json parse<commit_after>var WSS = require('ws').Server;

function json(name, args) {
  var obj = {
    name: name,
    args: args
  };
  this.send(JSON.stringify(obj));
}

function error(msg) {
  this.json('error', msg);
  this.close();
}

function message(message) {
  try {
    message = JSON.parse(message);
    this.emit.apply(this, message);
  } catch (err) {
    console.log(err);
  }
}

function logError(err) {
  console.log(err);
}

function decorate(ws) {
  ws.json = json;
  ws.error = error;
  ws.on('message', message);
  ws.on('error', logError);
}

function wss(server) {
  var wss = new WSS({ server: server });
  wss.on('connection', decorate);
  return wss;
}

module.exports = wss;
{'fraction_non_alphanumeric': 0.17439293598233996, 'fraction_numerical': 0.0, 'mean_word_length': 3.641638225255973, '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': '3330752', 'n_tokens_mistral': 514, 'n_tokens_neox': 504, 'n_words': 108}