<commit_before>const remessageError = (error, nextMessage) => {
  error.stack && error.stack.replace(error.message, nextMessage) // NOTE: V8(Chrome/Nodejs) will save a copy of message in the `.stack` for simpler `.toString()`, but FireFox will compose correctly
  error.message = nextMessage
  return error
}

const rethrowError = (error) => {
  console.warn(error)
  throw error
}

const tryCall = (thisArg, name, ...args) => {
  try {
    return thisArg[ name ](...args)
  } catch (error) { __DEV__ && console.log('[tryCall] failed:', name, error) }
}

// for better flow control
const catchSync = (func, ...args) => {
  let result, resultError
  try { result = func(...args) } catch (error) { resultError = error || new Error() }
  return { result, error: resultError }
}

const catchAsync = async (func, ...args) => {
  let result, resultError
  try { result = await func(...args) } catch (error) { resultError = error || new Error() }
  return { result, error: resultError }
}
// const catchAsync = (func, ...args) => { // NOTE: reference async-less implementation
//   try {
//     const possiblePromise = func(...args)
//     return catchPromise(possiblePromise)
//   } catch (error) { return Promise.resolve(packError(error)) }
// }

const catchPromise = (promise) => promise.then(packResult, packError)
const packResult = (result) => ({ result, error: undefined })
const packError = (error) => ({ result: undefined, error: error || new Error() })

export {
  remessageError,
  rethrowError,
  tryCall,
  catchSync,
  catchAsync,
  catchPromise
}
<commit_msg>DEPRECATE: common: `tryCall`<commit_after>const remessageError = (error, nextMessage) => {
  error.stack && error.stack.replace(error.message, nextMessage) // NOTE: V8(Chrome/Nodejs) will save a copy of message in the `.stack` for simpler `.toString()`, but FireFox will compose correctly
  error.message = nextMessage
  return error
}

const rethrowError = (error) => {
  console.warn(error)
  throw error
}

/** @deprecated */ const tryCall = (thisArg, name, ...args) => { // TODO: DEPRECATE
  try {
    return thisArg[ name ](...args)
  } catch (error) { __DEV__ && console.log('[tryCall] failed:', name, error) }
}

// for better flow control
const catchSync = (func, ...args) => {
  let result, resultError
  try { result = func(...args) } catch (error) { resultError = error || new Error() }
  return { result, error: resultError }
}

const catchAsync = async (func, ...args) => {
  let result, resultError
  try { result = await func(...args) } catch (error) { resultError = error || new Error() }
  return { result, error: resultError }
}
// const catchAsync = (func, ...args) => { // NOTE: reference async-less implementation
//   try {
//     const possiblePromise = func(...args)
//     return catchPromise(possiblePromise)
//   } catch (error) { return Promise.resolve(packError(error)) }
// }

const catchPromise = (promise) => promise.then(packResult, packError)
const packResult = (result) => ({ result, error: undefined })
const packError = (error) => ({ result: undefined, error: error || new Error() })

export {
  remessageError,
  rethrowError,
  tryCall, // TODO: DEPRECATE
  catchSync,
  catchAsync,
  catchPromise
}

{'fraction_non_alphanumeric': 0.1553337492202121, 'fraction_numerical': 0.0006238303181534623, 'mean_word_length': 3.6613372093023258, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '4974309', 'n_tokens_mistral': 987, 'n_tokens_neox': 981, 'n_words': 295}