<commit_before>const {EventEmitter} = require('events')
const bindings = process.atomBinding('session')

const PERSIST_PREFIX = 'persist:'

// Returns the Session from |partition| string.
exports.fromPartition = function (partition = '') {
  if (partition === '') return exports.defaultSession

  if (partition.startsWith(PERSIST_PREFIX)) {
    return bindings.fromPartition(partition.substr(PERSIST_PREFIX.length), false)
  } else {
    return bindings.fromPartition(partition, true)
  }
}

// Returns the default session.
Object.defineProperty(exports, 'defaultSession', {
  enumerable: true,
  get: function () {
    return bindings.fromPartition('', false)
  }
})

const wrapSession = function (session) {
  // Session is an EventEmitter.
  Object.setPrototypeOf(session, EventEmitter.prototype)
}
<commit_msg>Throw error when session module is used before app is ready<commit_after>const {EventEmitter} = require('events')
const electron = require('electron')
const bindings = process.atomBinding('session')

const PERSIST_PREFIX = 'persist:'

// Wrapper of binding.fromPartition that checks for ready event.
const fromPartition = function (partition, persist) {
  if (!electron.app.isReady()) {
    throw new Error('session module can only be used when app is ready')
  }

  return bindings.fromPartition(partition, persist)
}

// Returns the Session from |partition| string.
exports.fromPartition = function (partition = '') {
  if (partition === '') return exports.defaultSession

  if (partition.startsWith(PERSIST_PREFIX)) {
    return fromPartition(partition.substr(PERSIST_PREFIX.length), false)
  } else {
    return fromPartition(partition, true)
  }
}

// Returns the default session.
Object.defineProperty(exports, 'defaultSession', {
  enumerable: true,
  get: function () {
    return fromPartition('', false)
  }
})

const wrapSession = function (session) {
  // Session is an EventEmitter.
  Object.setPrototypeOf(session, EventEmitter.prototype)
}

{'fraction_non_alphanumeric': 0.11731843575418995, 'fraction_numerical': 0.0, 'mean_word_length': 4.845697329376854, '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': '784155', 'n_tokens_mistral': 554, 'n_tokens_neox': 548, 'n_words': 151}