<commit_before>'use strict';

let path = require('path');
let domain = require('domain');
let url = require('url');

let Promise = require('bluebird');
let _ = require('lodash');
let dependencyGraph = require('dependency-graph');

let DigsEmitter = require('digs-common/digs-emitter');

let Plugins = require('./plugins');
let pkg = require('../package.json');
let DigsClient = require('./client');

let debug = require('debug')('digs:digs');

const INTERNAL_BROKER_MODULE = 'digs-mqtt-broker';

const DEFAULTS = {
  namespace: pkg.name,
  project: 'home',
  autoDetectPlugins: false,
  autoStart: false,
  pluginOptions: {},
  broker: {
    type: INTERNAL_BROKER_MODULE,
    json: false,
    url: 'mqtt://localhost:1883'
  }
};

/**
 * Plugin class
 */
class Digs extends DigsEmitter {

  /**
   * Instantiates Digs
   * @constructor
   */
  constructor(opts) {
    super();

    /**
     * Plugin Configuration
     * @type {Object}
     */
    opts = _.defaults(opts || {}, DEFAULTS);
    opts.broker = _.defaults(opts.broker, DEFAULTS.broker);

    this._opts = opts;
    this._domain = domain.create();
    this._domain.add(this);
    this._unloadedPlugins = {};
    this._graph = new dependencyGraph.DepGraph();
    this._broker = null;
    this._client = null;
    this._ready = null;

    debug(`${this}: instantiated w/ options:`, opts);

    if (opts.autoStart) {
      this.start();
    }
  }

  _detect() {
    return Promise.bind(this)
      .then(function () {
        return Plugins.autoDetect(path.join(__dirname, '..', '..'));
      })
      .then(this.use);
  }

  get isReady() {
    return !!this._ready && this._ready.isFulfilled();
  }

  get id() {
    return this.project;
  }

  get project() {
    return this._opts.project;
  }

  get namespace() {<commit_msg>catch autodetection errors in _detect()<commit_after>'use strict';

let path = require('path');
let domain = require('domain');
let url = require('url');

let Promise = require('bluebird');
let _ = require('lodash');
let dependencyGraph = require('dependency-graph');

let DigsEmitter = require('digs-common/digs-emitter');

let Plugins = require('./plugins');
let pkg = require('../package.json');
let DigsClient = require('./client');

let debug = require('debug')('digs:digs');

const INTERNAL_BROKER_MODULE = 'digs-mqtt-broker';

const DEFAULTS = {
  namespace: pkg.name,
  project: 'home',
  autoDetectPlugins: false,
  autoStart: false,
  pluginOptions: {},
  broker: {
    type: INTERNAL_BROKER_MODULE,
    json: false,
    url: 'mqtt://localhost:1883'
  }
};

/**
 * Plugin class
 */
class Digs extends DigsEmitter {

  /**
   * Instantiates Digs
   * @constructor
   */
  constructor(opts) {
    super();

    /**
     * Plugin Configuration
     * @type {Object}
     */
    opts = _.defaults(opts || {}, DEFAULTS);
    opts.broker = _.defaults(opts.broker, DEFAULTS.broker);

    this._opts = opts;
    this._domain = domain.create();
    this._domain.add(this);
    this._unloadedPlugins = {};
    this._graph = new dependencyGraph.DepGraph();
    this._broker = null;
    this._client = null;
    this._ready = null;

    debug(`${this}: instantiated w/ options:`, opts);

    if (opts.autoStart) {
      this.start();
    }
  }

  _detect() {
    return Promise.bind(this)
      .then(function () {
        return Plugins.autoDetect(path.join(__dirname, '..', '..'));
      })
      .then(this.use)
      .catch(function () {
        debug('Failed to autodetect external plugins');
      });
  }

  get isReady() {
    return !!this._ready && this._ready.isFulfilled();
  }

  get id() {
    return this.project;
  }

  get project() {
    return this._opts.project;
  }

  get namespace() {
{'fraction_non_alphanumeric': 0.16630552546045504, 'fraction_numerical': 0.0021668472372697724, 'mean_word_length': 3.0184983677910773, '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': '2424679', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1204, 'n_words': 252}