Skip to content
Myr

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 file

Take it

reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764

line 1why, one step back
1'use strict';

Require Node.js 6Sindre Sorhusbefore adoption49518e1

line 2why, one step back
2// 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 back
3// 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 back
6let uv;

reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764

line 7why, one step back
7

Avoid relying on Node’s internals (#125)Anna Henningsenbefore adoption51a45df

lines 8–11why, one step back
8if (typeof util.getSystemErrorName === 'function') {
9 module.exports = util.getSystemErrorName;10} else {11 try {

Require Node.js 8Sindre Sorhusbefore adoptiondce2267

line 12why, one step back
12 uv = process.binding('uv'); // eslint-disable-line node/no-deprecated-api

reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764

line 13why, one step back
13

Avoid relying on Node’s internals (#125)Anna Henningsenbefore adoption51a45df

lines 14–16why, one step back
14 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 back
17 } 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 back
19 uv = undefined;

reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764

line 20why, one step back
20 }

Avoid relying on Node’s internals (#125)Anna Henningsenbefore adoption51a45df

lines 21–22why, one step back
21
22 module.exports = code => errname(uv, code);

reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764

lines 23–24why, one step back
23}
24

Avoid relying on Node’s internals (#125)Anna Henningsenbefore adoption51a45df

lines 25–27why, one step back
25// Used for testing the fallback behavior
26module.exports.__test__ = errname;27

reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764

line 28why, one step back
28function errname(uv, code) {

Replace `null` by `undefined` (#193)ehmickybefore adoptiondca1504

line 29why, one step back
29 if (uv !== undefined) {

reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764

lines 30–36why, one step back
30 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 back
37 return `Unknown system error ${code}`;

reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764

lines 38–39why, one step back
38}
39