Skip to content

Commit

Permalink
Fix EBADPLATFORM error message (#1876)
Browse files Browse the repository at this point in the history
* Fix EBADPLATFORM error message

Error format evolved out from under message generation's
expectations.

* Fix formatting
  • Loading branch information
Brian Jenkins authored Sep 29, 2020
1 parent 9bc6966 commit 405e051
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
8 changes: 6 additions & 2 deletions lib/utils/error-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
4 changes: 2 additions & 2 deletions tap-snapshots/test-lib-utils-error-message.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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\\"})",
],
],
}
Expand All @@ -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\\"})",
],
],
}
Expand Down
22 changes: 18 additions & 4 deletions test/lib/utils/error-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,17 +406,31 @@ 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))
t.end()
})
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))
Expand Down

0 comments on commit 405e051

Please sign in to comment.