function extract (stats, severity) {
  const type = severity + 's'

  const findErrorsRecursive = compilation => {
    const errors = compilation[ type ]
    if (errors.length === 0 && compilation.children) {
      for (const child of compilation.children) {
        errors.push(...findErrorsRecursive(child))
      }
    }

    return uniqueBy(errors, error => error.message)
  }

  return findErrorsRecursive(stats.compilation)
}
Initially forked from friendly-errors-webpack-plugin 2.0.0-beta.2