From 405e051f724a2e79844f78f8ea9ba019fdc513aa Mon Sep 17 00:00:00 2001 From: Brian Jenkins Date: Tue, 29 Sep 2020 10:59:23 -0700 Subject: [PATCH] Fix EBADPLATFORM error message (#1876) * Fix EBADPLATFORM error message Error format evolved out from under message generation's expectations. * Fix formatting --- lib/utils/error-message.js | 8 +++++-- ...est-lib-utils-error-message.js-TAP.test.js | 4 ++-- test/lib/utils/error-message.js | 22 +++++++++++++++---- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/utils/error-message.js b/lib/utils/error-message.js index 7f9aca95ef39c..a1e1caeeb4872 100644 --- a/lib/utils/error-message.js +++ b/lib/utils/error-message.js @@ -220,8 +220,12 @@ module.exports = (er) => { break case 'EBADPLATFORM': { - const validOs = er.os.join ? er.os.join(',') : er.os - const validArch = er.cpu.join ? er.cpu.join(',') : er.cpu + const validOs = er.required && + er.required.os && + er.required.os.join ? er.required.os.join(',') : er.required.os + const validArch = er.required && + er.required.cpu && + er.required.cpu.join ? er.required.cpu.join(',') : er.required.cpu const expected = { os: validOs, arch: validArch } const actual = { os: process.platform, arch: process.arch } short.push([ diff --git a/tap-snapshots/test-lib-utils-error-message.js-TAP.test.js b/tap-snapshots/test-lib-utils-error-message.js-TAP.test.js index 921cc06b99aa4..21fff0b87be09 100644 --- a/tap-snapshots/test-lib-utils-error-message.js-TAP.test.js +++ b/tap-snapshots/test-lib-utils-error-message.js-TAP.test.js @@ -161,7 +161,7 @@ Object { "summary": Array [ Array [ "notsup", - "Unsupported platform for undefined: wanted {\\"os\\":\\"!yours,mine\\",\\"arch\\":\\"x420,x69\\"} (current: {\\"os\\":\\"posix\\",\\"arch\\":\\"x64\\"})", + "Unsupported platform for lodash@1.0.0: wanted {\\"os\\":\\"!yours,mine\\",\\"arch\\":\\"x420,x69\\"} (current: {\\"os\\":\\"posix\\",\\"arch\\":\\"x64\\"})", ], ], } @@ -178,7 +178,7 @@ Object { "summary": Array [ Array [ "notsup", - "Unsupported platform for undefined: wanted {\\"os\\":\\"!yours\\",\\"arch\\":\\"x420\\"} (current: {\\"os\\":\\"posix\\",\\"arch\\":\\"x64\\"})", + "Unsupported platform for lodash@1.0.0: wanted {\\"os\\":\\"!yours\\",\\"arch\\":\\"x420\\"} (current: {\\"os\\":\\"posix\\",\\"arch\\":\\"x64\\"})", ], ], } diff --git a/test/lib/utils/error-message.js b/test/lib/utils/error-message.js index 14d75e31ec6f5..46df017f4847a 100644 --- a/test/lib/utils/error-message.js +++ b/test/lib/utils/error-message.js @@ -406,8 +406,15 @@ t.test('404', t => { t.test('bad platform', t => { t.test('string os/arch', t => { const er = Object.assign(new Error('a bad plat'), { - os: '!yours', - cpu: 'x420', + pkgid: 'lodash@1.0.0', + current: { + os: 'posix', + cpu: 'x64' + }, + required: { + os: '!yours', + cpu: 'x420' + }, code: 'EBADPLATFORM' }) t.matchSnapshot(errorMessage(er)) @@ -415,8 +422,15 @@ t.test('bad platform', t => { }) t.test('array os/arch', t => { const er = Object.assign(new Error('a bad plat'), { - os: ['!yours', 'mine'], - cpu: ['x420', 'x69'], + pkgid: 'lodash@1.0.0', + current: { + os: 'posix', + cpu: 'x64' + }, + required: { + os: ['!yours', 'mine'], + cpu: ['x420', 'x69'] + }, code: 'EBADPLATFORM' }) t.matchSnapshot(errorMessage(er))