errname.js
This file
Path
lib/errname.js
39 lines · 910 bytes · JavaScript
Last changed by
Replace `null` by `undefined` (#193)ehmickybefore adoptiondca1504
History of this fileTake it
reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764
line 1why, one step back1'use strict';Require Node.js 6Sindre Sorhusbefore adoption49518e1
line 2why, one step back2// Older verions of Node.js might not have `util.getSystemErrorName()`.Avoid relying on Node’s internals (#125)Anna Henningsenbefore adoption51a45df
lines 3–5why, one step back3// In that case, fall back to a deprecated internal.4const util = require('util');5[BREAKING] ES2015ify and require Node.js 4Sindre Sorhusbefore adoption8a7a51c
line 6why, one step back6let uv;reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764
line 7why, one step back7Avoid relying on Node’s internals (#125)Anna Henningsenbefore adoption51a45df
lines 8–11why, one step back8if (typeof util.getSystemErrorName === 'function') {9 module.exports = util.getSystemErrorName;10} else {11 try {Require Node.js 8Sindre Sorhusbefore adoptiondce2267
line 12why, one step back12 uv = process.binding('uv'); // eslint-disable-line node/no-deprecated-apireimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764
line 13why, one step back13Avoid relying on Node’s internals (#125)Anna Henningsenbefore adoption51a45df
lines 14–16why, one step back14 if (typeof uv.errname !== 'function') {15 throw new TypeError('uv.errname is not a function');16 }Fix lint issuesSindre Sorhusbefore adoptionb7752fb
lines 17–18why, one step back17 } catch (error) {18 console.error('execa/lib/errname: unable to establish process.binding(\'uv\')', error);Replace `null` by `undefined` (#193)ehmickybefore adoptiondca1504
line 19why, one step back19 uv = undefined;reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764
line 20why, one step back20 }Avoid relying on Node’s internals (#125)Anna Henningsenbefore adoption51a45df
lines 21–22why, one step back2122 module.exports = code => errname(uv, code);reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764
lines 23–24why, one step back23}24Avoid relying on Node’s internals (#125)Anna Henningsenbefore adoption51a45df
lines 25–27why, one step back25// Used for testing the fallback behavior26module.exports.__test__ = errname;27reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764
line 28why, one step back28function errname(uv, code) {Replace `null` by `undefined` (#193)ehmickybefore adoptiondca1504
line 29why, one step back29 if (uv !== undefined) {reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764
lines 30–36why, one step back30 return uv.errname(code);31 }3233 if (!(code < 0)) {34 throw new Error('err >= 0');35 }36[BREAKING] ES2015ify and require Node.js 4Sindre Sorhusbefore adoption8a7a51c
line 37why, one step back37 return `Unknown system error ${code}`;reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764
lines 38–39why, one step back38}39