Skip to content

Commit

Permalink
fixup! EUSAGE for npm pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Nov 4, 2021
1 parent bd8f91a commit 9c20f05
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
10 changes: 2 additions & 8 deletions lib/commands/pkg.js
Expand Up @@ -96,10 +96,7 @@ class Pkg extends BaseCommand {

async set (args) {
const setError = () =>
Object.assign(
new TypeError('npm pkg set expects a key=value pair of args.'),
{ code: 'EPKGSET' }
)
this.usageError('npm pkg set expects a key=value pair of args.')

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

async delete (args) {
const setError = () =>
Object.assign(
new TypeError('npm pkg delete expects key args.'),
{ code: 'EPKGDELETE' }
)
this.usageError('npm pkg delete expects key args.')

if (!args.length)
throw setError()
Expand Down
4 changes: 4 additions & 0 deletions packages/libnpmdiff/index.js
Expand Up @@ -4,6 +4,10 @@ const formatDiff = require('./lib/format-diff.js')
const getTarball = require('./lib/tarball.js')
const untar = require('./lib/untar.js')

// TODO: we test this condition in the diff command
// so this error probably doesnt need to be here. Or
// if it does we should figure out a standard code
// so we can catch it in the cli and display it consistently
const argsError = () =>
Object.assign(
new TypeError('libnpmdiff needs two arguments to compare'),
Expand Down
10 changes: 5 additions & 5 deletions test/lib/commands/pkg.js
Expand Up @@ -196,7 +196,7 @@ t.test('set no args', async t => {
})
await t.rejects(
pkg.exec(['set']),
{ code: 'EPKGSET' },
{ code: 'EUSAGE' },
'should throw an error if no args'
)
})
Expand All @@ -207,7 +207,7 @@ t.test('set missing value', async t => {
})
await t.rejects(
pkg.exec(['set', 'key=']),
{ code: 'EPKGSET' },
{ code: 'EUSAGE' },
'should throw an error if missing value'
)
})
Expand All @@ -218,7 +218,7 @@ t.test('set missing key', async t => {
})
await t.rejects(
pkg.exec(['set', '=value']),
{ code: 'EPKGSET' },
{ code: 'EUSAGE' },
'should throw an error if missing key'
)
})
Expand Down Expand Up @@ -424,7 +424,7 @@ t.test('delete no args', async t => {
})
await t.rejects(
pkg.exec(['delete']),
{ code: 'EPKGDELETE' },
{ code: 'EUSAGE' },
'should throw an error if deleting no args'
)
})
Expand All @@ -435,7 +435,7 @@ t.test('delete invalid key', async t => {
})
await t.rejects(
pkg.exec(['delete', '']),
{ code: 'EPKGDELETE' },
{ code: 'EUSAGE' },
'should throw an error if deleting invalid args'
)
})
Expand Down

0 comments on commit 9c20f05

Please sign in to comment.