From f8ab0e800613ae740971d897386bb2ba0c93d772 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Tue, 7 May 2019 15:38:56 +0200 Subject: [PATCH 1/2] Remove util.getSystemErrorName() compatibility layer --- lib/errname.js | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/lib/errname.js b/lib/errname.js index 151c53fea3..c8c76e642b 100644 --- a/lib/errname.js +++ b/lib/errname.js @@ -1,35 +1,12 @@ 'use strict'; -// Older verions of Node.js might not have `util.getSystemErrorName()`. -// In that case, fall back to a deprecated internal. const util = require('util'); -let uv; - -if (typeof util.getSystemErrorName === 'function') { - module.exports = util.getSystemErrorName; -} else { - try { - uv = process.binding('uv'); // eslint-disable-line node/no-deprecated-api - - if (typeof uv.errname !== 'function') { - throw new TypeError('uv.errname is not a function'); - } - } catch (error) { - console.error('execa/lib/errname: unable to establish process.binding(\'uv\')', error); - uv = undefined; - } - - module.exports = code => errname(uv, code); -} +module.exports = util.getSystemErrorName; // Used for testing the fallback behavior module.exports.__test__ = errname; function errname(uv, code) { - if (uv !== undefined) { - return uv.errname(code); - } - if (!(code < 0)) { throw new Error('err >= 0'); } From 070028f41c0a205e16bb32f33776599a123cd9cb Mon Sep 17 00:00:00 2001 From: ehmicky Date: Tue, 7 May 2019 15:41:12 +0200 Subject: [PATCH 2/2] Remove `lib/errname.js` --- index.js | 4 ++-- lib/errname.js | 16 ---------------- test/errname.js | 26 -------------------------- 3 files changed, 2 insertions(+), 44 deletions(-) delete mode 100644 lib/errname.js delete mode 100644 test/errname.js diff --git a/index.js b/index.js index 6261c3abfd..8ee4d97cb0 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ 'use strict'; const path = require('path'); const os = require('os'); +const util = require('util'); const childProcess = require('child_process'); const crossSpawn = require('cross-spawn'); const stripFinalNewline = require('strip-final-newline'); @@ -10,7 +11,6 @@ const _getStream = require('get-stream'); const mergeStream = require('merge-stream'); const pFinally = require('p-finally'); const onExit = require('signal-exit'); -const errname = require('./lib/errname'); const stdio = require('./lib/stdio'); const TEN_MEGABYTES = 1000 * 1000 * 10; @@ -220,7 +220,7 @@ function getCode({error = {}}, code) { } if (Number.isInteger(code)) { - return [errname(-Math.abs(code)), Math.abs(code)]; + return [util.getSystemErrorName(-Math.abs(code)), Math.abs(code)]; } return []; diff --git a/lib/errname.js b/lib/errname.js deleted file mode 100644 index c8c76e642b..0000000000 --- a/lib/errname.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict'; -const util = require('util'); - -module.exports = util.getSystemErrorName; - -// Used for testing the fallback behavior -module.exports.__test__ = errname; - -function errname(uv, code) { - if (!(code < 0)) { - throw new Error('err >= 0'); - } - - return `Unknown system error ${code}`; -} - diff --git a/test/errname.js b/test/errname.js deleted file mode 100644 index 001c148359..0000000000 --- a/test/errname.js +++ /dev/null @@ -1,26 +0,0 @@ -import test from 'ava'; -import errname from '../lib/errname'; - -const isWindows = process.platform === 'win32'; - -// Simulates failure to capture `process.binding('uv');` -const fallback = code => errname.__test__(undefined, code); - -function makeTests(name, m, expected) { - test(`${name}: >=0 exit codes`, t => { - // Throws >= 0 - t.throws(() => m(0), /err >= 0|It must be a negative integer|must be of type negative number/); - t.throws(() => m(1), /err >= 0|It must be a negative integer|must be of type negative number/); - t.throws(() => m('2'), /err >= 0|must be of type number|must be of type negative number/); - t.throws(() => m('foo'), /err >= 0|must be of type number|must be of type negative number/); - }); - - test(`${name}: negative exit codes`, t => { - t.is(m(-2), expected); - }); -} - -const unknown = 'Unknown system error -2'; - -makeTests('native', errname, isWindows ? unknown : 'ENOENT'); -makeTests('fallback', fallback, unknown);