<commit_before>import {isUndefined, isFunction, isArray} from 'lodash/lang';

export function createMockWorkers() {
  return {
    callFunction({filename, name, args}, cb) {
      let mod;
      try {
        mod = require(filename);
      } catch(err) {
        return cb(err);
      }

      if (isUndefined(mod[name]) || !isFunction(mod[name])) {
        return cb(new Error(`Module ${filename} does not export a function named ${name}`));
      }

      if (!isArray(args)) {
        return cb(new Error(`\`args\` option ${args} must be an array`));
      }

      mod[name].apply(global, args.concat([cb]));
    }
  }
}<commit_msg>Catch issues with malformed worker function invocations<commit_after>import {isUndefined, isFunction, isArray} from 'lodash/lang';

export function createMockWorkers() {
  return {
    callFunction({filename, name, args}, cb) {
      if (isUndefined(filename)) {
        return cb(new Error('The `filename` property has not been defined'));
      }

      let mod;
      try {
        mod = require(filename);
      } catch(err) {
        return cb(err);
      }

      if (isUndefined(mod[name]) || !isFunction(mod[name])) {
        return cb(new Error(`Module ${filename} does not export a function named ${name}`));
      }

      if (!isArray(args)) {
        return cb(new Error(`\`args\` option ${args} must be an array`));
      }

      mod[name].apply(global, args.concat([cb]));
    }
  }
}
{'fraction_non_alphanumeric': 0.1511142061281337, 'fraction_numerical': 0.0, 'mean_word_length': 2.751958224543081, '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': '4093204', 'n_tokens_mistral': 444, 'n_tokens_neox': 436, 'n_words': 115}