<commit_before>/*! Copyright (c) 2016 <NAME> | MIT Licensed */
'use strict'

/**
 * Module dependencies.
 *
 * @private
 */
const debug = require('debug')('ccr:on-incoming')

const Request = require('./request')

/**
 * Handles all incoming comunication
 *
 * @private
 */
function onIncoming (connection) {
  // Be verbose while debugging
  debug('Opened for %s', connection._cluster ? 'Hub'
  : `Worker on Channel ${connection.channel}`)

  // Return event
  return (worker, message) => {
    // Only the hub knows the worker
    if (message === undefined) {
      message = worker
      worker = connection._worker
    }

    let key = message.key
    let who = connection.channel !== undefined
    ? 'Worker' : 'Hub'
    let channel = connection.channel !== undefined
    ? connection.channel : connection._channels[worker.id]

    // Only requests have a path defined.
    if (message.path !== undefined) {
      debug('%s got a request %s on Channel %s', who, key, channel)
      onRequest(connection, worker, message)
    } else {
      debug('%s got a response for %s on Channel %s', who, key, channel)
      onResponse(connection, message)
    }
  }
}
// Export function
module.exports = onIncoming

/**
 * Fires only on request messages
 */
function onRequest (connection, worker, message) {
  // Create a new request
  let req = new Request(connection, worker, message)

  // Set the final handler, hopefully we don't reach it.
  let done = err => {
    // Ignore ghost requests (handled requests without error)
    if (!err && req._sent) {
      debug('Ignoring ghost request')
      return
    }

    let type = err ? 'wronged' : 'unhandled'

    debug('Responding to %s request %s', type, req.key)

    // Print error if not testing
    if (err) {
      if (connection.get('env') !== 'test') {
        console.log(err)
      }

    // Exit here if request is sent
    } else if (req._sent) {
      debug('Can only respond if request %s is not sent', req.key)

      return

    // Unhandled request need a guide (error)
    } else {
      err = new Error('Cannot find ' + (req.originalPath || req.path))
    }

    // Send response
    debug('Sending respons for %s request %s', type, req.key)
    req.send(err)
  }

  // No routes defined
  if (!connection._router) {
    debug('Cannot respond to requests until after routes are defined')
    done()
    return
  }<commit_msg>Added dobble quote to path<commit_after>/*! Copyright (c) 2016 <NAME> | MIT Licensed */
'use strict'

/**
 * Module dependencies.
 *
 * @private
 */
const debug = require('debug')('ccr:on-incoming')

const Request = require('./request')

/**
 * Handles all incoming comunication
 *
 * @private
 */
function onIncoming (connection) {
  // Be verbose while debugging
  debug('Opened for %s', connection._cluster ? 'Hub'
  : `Worker on Channel ${connection.channel}`)

  // Return event
  return (worker, message) => {
    // Only the hub knows the worker
    if (message === undefined) {
      message = worker
      worker = connection._worker
    }

    let key = message.key
    let who = connection.channel !== undefined
    ? 'Worker' : 'Hub'
    let channel = connection.channel !== undefined
    ? connection.channel : connection._channels[worker.id]

    // Only requests have a path defined.
    if (message.path !== undefined) {
      debug('%s got a request %s on Channel %s', who, key, channel)
      onRequest(connection, worker, message)
    } else {
      debug('%s got a response for %s on Channel %s', who, key, channel)
      onResponse(connection, message)
    }
  }
}
// Export function
module.exports = onIncoming

/**
 * Fires only on request messages
 */
function onRequest (connection, worker, message) {
  // Create a new request
  let req = new Request(connection, worker, message)

  // Set the final handler, hopefully we don't reach it.
  let done = err => {
    // Ignore ghost requests (handled requests without error)
    if (!err && req._sent) {
      debug('Ignoring ghost request')
      return
    }

    let type = err ? 'wronged' : 'unhandled'

    debug('Responding to %s request %s', type, req.key)

    // Print error if not testing
    if (err) {
      if (connection.get('env') !== 'test') {
        console.log(err)
      }

    // Exit here if request is sent
    } else if (req._sent) {
      debug('Can only respond if request %s is not sent', req.key)

      return

    // Unhandled request need a guide (error)
    } else {
      err = new Error(`Cannot find "${req.originalPath || req.path}"`)
    }

    // Send response
    debug('Sending respons for %s request %s', type, req.key)
    req.send(err)
  }

  // No routes defined
  if (!connection._router) {
    debug('Cannot respond to requests until after routes are defined')
    done()
    return
  }
{'fraction_non_alphanumeric': 0.12888425443169968, 'fraction_numerical': 0.0016684045881126173, 'mean_word_length': 2.6920708237105466, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '2596355', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1384, 'n_words': 490}