You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

errname.js 976B

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. // The Node team wants to deprecate `process.bind(...)`.
  3. // https://github.com/nodejs/node/pull/2768
  4. //
  5. // However, we need the 'uv' binding for errname support.
  6. // This is a defensive wrapper around it so `execa` will not fail entirely if it stops working someday.
  7. //
  8. // If this ever stops working. See: https://github.com/sindresorhus/execa/issues/31#issuecomment-215939939 for another possible solution.
  9. let uv;
  10. try {
  11. uv = process.binding('uv');
  12. if (typeof uv.errname !== 'function') {
  13. throw new TypeError('uv.errname is not a function');
  14. }
  15. } catch (err) {
  16. console.error('execa/lib/errname: unable to establish process.binding(\'uv\')', err);
  17. uv = null;
  18. }
  19. function errname(uv, code) {
  20. if (uv) {
  21. return uv.errname(code);
  22. }
  23. if (!(code < 0)) {
  24. throw new Error('err >= 0');
  25. }
  26. return `Unknown system error ${code}`;
  27. }
  28. module.exports = code => errname(uv, code);
  29. // Used for testing the fallback behavior
  30. module.exports.__test__ = errname;