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
reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764
lines 1–8why, one step back1'use strict';2// The Node team wants to deprecate `process.bind(...)`.3// https://github.com/nodejs/node/pull/27684//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.[BREAKING] ES2015ify and require Node.js 4Sindre Sorhusbefore adoption8a7a51c
line 9why, one step back9let uv;reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764
lines 10–30why, one step back1011try {12 uv = process.binding('uv');1314 if (typeof uv.errname !== 'function') {15 throw new Error('uv.errname is not a function');16 }17} catch (err) {18 console.error('execa/lib/errname: unable to establish process.binding(\'uv\')', err);19 uv = null;20}2122function errname(uv, code) {23 if (uv) {24 return uv.errname(code);25 }2627 if (!(code < 0)) {28 throw new Error('err >= 0');29 }30[BREAKING] ES2015ify and require Node.js 4Sindre Sorhusbefore adoption8a7a51c
line 31why, one step back31 return `Unknown system error ${code}`;reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764
lines 32–33why, one step back32}33[BREAKING] ES2015ify and require Node.js 4Sindre Sorhusbefore adoption8a7a51c
line 34why, one step back34module.exports = code => errname(uv, code);reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764
line 35why, one step back35[BREAKING] ES2015ify and require Node.js 4Sindre Sorhusbefore adoption8a7a51c
line 36why, one step back36// used for testing the fallback behaviorreimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764
line 37why, one step back37module.exports.__test__ = errname;