errname.js
This file
Path
lib/errname.js
37 lines · 972 bytes · JavaScript
Last changed by
[BREAKING] ES2015ify and require Node.js 4Sindre Sorhusbefore adoption8a7a51c
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738'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') { throw new Error('uv.errname is not a function'); }} 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);
// used for testing the fallback behaviormodule.exports.__test__ = errname;