2017-05-28 00:38:50 +02:00
|
|
|
'use strict';
|
|
|
|
// The Node team wants to deprecate `process.bind(...)`.
|
|
|
|
// https://github.com/nodejs/node/pull/2768
|
|
|
|
//
|
|
|
|
// However, we need the 'uv' binding for errname support.
|
|
|
|
// This is a defensive wrapper around it so `execa` will not fail entirely if it stops working someday.
|
|
|
|
//
|
|
|
|
// If this ever stops working. See: https://github.com/sindresorhus/execa/issues/31#issuecomment-215939939 for another possible solution.
|
|
|
|
let uv;
|
|
|
|
|
|
|
|
try {
|
|
|
|
uv = process.binding('uv');
|
|
|
|
|
|
|
|
if (typeof uv.errname !== 'function') {
|
2017-08-14 05:01:11 +02:00
|
|
|
throw new TypeError('uv.errname is not a function');
|
2017-05-28 00:38:50 +02:00
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.error('execa/lib/errname: unable to establish process.binding(\'uv\')', err);
|
|
|
|
uv = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function errname(uv, code) {
|
|
|
|
if (uv) {
|
|
|
|
return uv.errname(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(code < 0)) {
|
|
|
|
throw new Error('err >= 0');
|
|
|
|
}
|
|
|
|
|
|
|
|
return `Unknown system error ${code}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = code => errname(uv, code);
|
|
|
|
|
2017-08-14 05:01:11 +02:00
|
|
|
// Used for testing the fallback behavior
|
2017-05-28 00:38:50 +02:00
|
|
|
module.exports.__test__ = errname;
|