and-add-parent-to-errors.js 375 B

1234567891011121314
  1. 'use strict'
  2. var moduleName = require('../utils/module-name.js')
  3. var validate = require('aproba')
  4. module.exports = function (parent, cb) {
  5. validate('F', [cb])
  6. return function (er) {
  7. if (!er) return cb.apply(null, arguments)
  8. if (er instanceof Error && parent && parent.package && parent.package.name) {
  9. er.parent = moduleName(parent)
  10. }
  11. cb(er)
  12. }
  13. }