From 9c20f0537c4dc700a4aa43eaaae571464cd6aca1 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Thu, 4 Nov 2021 12:57:33 -0700 Subject: [PATCH] fixup! EUSAGE for npm pkg --- lib/commands/pkg.js | 10 ++-------- packages/libnpmdiff/index.js | 4 ++++ test/lib/commands/pkg.js | 10 +++++----- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/commands/pkg.js b/lib/commands/pkg.js index c9b8f7d40d047..1fa2c3bc5777b 100644 --- a/lib/commands/pkg.js +++ b/lib/commands/pkg.js @@ -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() @@ -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() diff --git a/packages/libnpmdiff/index.js b/packages/libnpmdiff/index.js index 73dc3ee64e3ce..2d074c3d1bb67 100644 --- a/packages/libnpmdiff/index.js +++ b/packages/libnpmdiff/index.js @@ -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'), diff --git a/test/lib/commands/pkg.js b/test/lib/commands/pkg.js index 784ea747010f4..49234e4cce323 100644 --- a/test/lib/commands/pkg.js +++ b/test/lib/commands/pkg.js @@ -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' ) }) @@ -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' ) }) @@ -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' ) }) @@ -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' ) }) @@ -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' ) })