Skip to content

Commit 9c20f05

Browse files
committed
fixup! EUSAGE for npm pkg
1 parent bd8f91a commit 9c20f05

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

lib/commands/pkg.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ class Pkg extends BaseCommand {
9696

9797
async set (args) {
9898
const setError = () =>
99-
Object.assign(
100-
new TypeError('npm pkg set expects a key=value pair of args.'),
101-
{ code: 'EPKGSET' }
102-
)
99+
this.usageError('npm pkg set expects a key=value pair of args.')
103100

104101
if (!args.length)
105102
throw setError()
@@ -123,10 +120,7 @@ class Pkg extends BaseCommand {
123120

124121
async delete (args) {
125122
const setError = () =>
126-
Object.assign(
127-
new TypeError('npm pkg delete expects key args.'),
128-
{ code: 'EPKGDELETE' }
129-
)
123+
this.usageError('npm pkg delete expects key args.')
130124

131125
if (!args.length)
132126
throw setError()

packages/libnpmdiff/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ const formatDiff = require('./lib/format-diff.js')
44
const getTarball = require('./lib/tarball.js')
55
const untar = require('./lib/untar.js')
66

7+
// TODO: we test this condition in the diff command
8+
// so this error probably doesnt need to be here. Or
9+
// if it does we should figure out a standard code
10+
// so we can catch it in the cli and display it consistently
711
const argsError = () =>
812
Object.assign(
913
new TypeError('libnpmdiff needs two arguments to compare'),

test/lib/commands/pkg.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ t.test('set no args', async t => {
196196
})
197197
await t.rejects(
198198
pkg.exec(['set']),
199-
{ code: 'EPKGSET' },
199+
{ code: 'EUSAGE' },
200200
'should throw an error if no args'
201201
)
202202
})
@@ -207,7 +207,7 @@ t.test('set missing value', async t => {
207207
})
208208
await t.rejects(
209209
pkg.exec(['set', 'key=']),
210-
{ code: 'EPKGSET' },
210+
{ code: 'EUSAGE' },
211211
'should throw an error if missing value'
212212
)
213213
})
@@ -218,7 +218,7 @@ t.test('set missing key', async t => {
218218
})
219219
await t.rejects(
220220
pkg.exec(['set', '=value']),
221-
{ code: 'EPKGSET' },
221+
{ code: 'EUSAGE' },
222222
'should throw an error if missing key'
223223
)
224224
})
@@ -424,7 +424,7 @@ t.test('delete no args', async t => {
424424
})
425425
await t.rejects(
426426
pkg.exec(['delete']),
427-
{ code: 'EPKGDELETE' },
427+
{ code: 'EUSAGE' },
428428
'should throw an error if deleting no args'
429429
)
430430
})
@@ -435,7 +435,7 @@ t.test('delete invalid key', async t => {
435435
})
436436
await t.rejects(
437437
pkg.exec(['delete', '']),
438-
{ code: 'EPKGDELETE' },
438+
{ code: 'EUSAGE' },
439439
'should throw an error if deleting invalid args'
440440
)
441441
})

0 commit comments

Comments
 (0)