<commit_before>'use strict'

import Path from 'path'
import { CACHE_KEY, KNOWN_SHELLS, assign, parse, applySugar, identifyEnvironment, identifyEnvironmentAsync } from './helpers'

module.exports = function() {
  if (process.platform === 'win32') {
    return assign({}, process.env)
  }
  if (global[CACHE_KEY]) {
    return assign({}, global[CACHE_KEY])
  }
  const shellName = Path.basename(process.env.SHELL)
  if (KNOWN_SHELLS.indexOf(shellName) === -1) {
    return assign({}, process.env)
  }
  const environment = applySugar(parse(identifyEnvironment()))
  global[CACHE_KEY] = environment
  return environment
}

module.exports.async = function() {
  return new Promise(function(resolve) {
    if (process.platform === 'win32') {
      resolve(assign({}, process.env))
    } else if (global[CACHE_KEY]) {
      resolve(assign({}, global[CACHE_KEY]))
    } else {
      const shellName = Path.basename(process.env.SHELL)
      if (KNOWN_SHELLS.indexOf(shellName) === -1) {
        resolve(assign({}, process.env))
      } else {
        resolve(identifyEnvironmentAsync().then(parse).then(applySugar).then(function(environment) {
          global[CACHE_KEY] = environment
          return environment
        }))
      }
    }
  })
}<commit_msg>:new: Swallow errors and log them in console<commit_after>'use strict'

import Path from 'path'
import { CACHE_KEY, KNOWN_SHELLS, assign, parse, applySugar, identifyEnvironment, identifyEnvironmentAsync } from './helpers'

module.exports = function() {
  if (process.platform === 'win32') {
    return assign({}, process.env)
  }
  if (global[CACHE_KEY]) {
    return assign({}, global[CACHE_KEY])
  }
  const shellName = Path.basename(process.env.SHELL)
  if (KNOWN_SHELLS.indexOf(shellName) === -1) {
    return assign({}, process.env)
  }
  try {
    const environment = applySugar(parse(identifyEnvironment()))
    global[CACHE_KEY] = environment
    return environment
  } catch (error) {
    console.error('[consistent-env] Unable to determine environment', error)
    return assign({}, process.env)
  }
}

module.exports.async = function() {
  return new Promise(function(resolve) {
    if (process.platform === 'win32') {
      resolve(assign({}, process.env))
    } else if (global[CACHE_KEY]) {
      resolve(assign({}, global[CACHE_KEY]))
    } else {
      const shellName = Path.basename(process.env.SHELL)
      if (KNOWN_SHELLS.indexOf(shellName) === -1) {
        resolve(assign({}, process.env))
      } else {
        resolve(identifyEnvironmentAsync().then(parse).then(applySugar).then(function(environment) {
          global[CACHE_KEY] = environment
          return environment
        }))
      }
    }
  }).catch(function(error) {
    console.error('[consistent-env] Unable to determine environment', error)
    return assign({}, process.env)
  })
}
{'fraction_non_alphanumeric': 0.1448300283286119, 'fraction_numerical': 0.00424929178470255, 'mean_word_length': 3.616013071895425, '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': '858896', 'n_tokens_mistral': 877, 'n_tokens_neox': 865, 'n_words': 179}