Skip to content

Commit

Permalink
fix(usage): add action items to error output
Browse files Browse the repository at this point in the history
PR-URL: #2917
Credit: @wraithgar
Close: #2917
Reviewed-by: @ruyadorno
  • Loading branch information
wraithgar authored and ruyadorno committed Mar 22, 2021
1 parent e1b3b31 commit 93a061d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/cli.js
Expand Up @@ -67,7 +67,7 @@ module.exports = (process) => {
if (cmd) {
const didYouMean = require('./utils/did-you-mean.js')
const suggestions = await didYouMean(npm, npm.localPrefix, cmd)
npm.output(`Unknown command: "${cmd}"${suggestions}`)
npm.output(`Unknown command: "${cmd}"${suggestions}\n\nTo see a list of supported npm commands, run:\n npm help`)
} else
npm.output(npm.usage)
process.exitCode = 1
Expand Down
2 changes: 1 addition & 1 deletion lib/run-script.js
Expand Up @@ -91,7 +91,7 @@ class RunScript extends BaseCommand {
return

const suggestions = await didYouMean(this.npm, path, event)
throw new Error(`Missing script: "${event}"${suggestions}`)
throw new Error(`Missing script: "${event}"${suggestions}\n\nTo see a list of scripts, run:\n npm run`)
}

// positional args only added to the main event, not pre/post
Expand Down
16 changes: 8 additions & 8 deletions test/lib/run-script.js
Expand Up @@ -896,27 +896,27 @@ t.test('workspaces', t => {
t.match(RUN_SCRIPTS, [])
t.strictSame(LOG.map(cleanOutput), [
'Lifecycle script `missing-script` failed with error:',
'Error: Missing script: "missing-script"',
'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run',
' in workspace: a@1.0.0',
' at location: {CWD}/test/lib/run-script-workspaces/packages/a',
'Lifecycle script `missing-script` failed with error:',
'Error: Missing script: "missing-script"',
'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run',
' in workspace: b@2.0.0',
' at location: {CWD}/test/lib/run-script-workspaces/packages/b',
'Lifecycle script `missing-script` failed with error:',
'Error: Missing script: "missing-script"',
'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run',
' in workspace: c@1.0.0',
' at location: {CWD}/test/lib/run-script-workspaces/packages/c',
'Lifecycle script `missing-script` failed with error:',
'Error: Missing script: "missing-script"',
'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run',
' in workspace: d@1.0.0',
' at location: {CWD}/test/lib/run-script-workspaces/packages/d',
'Lifecycle script `missing-script` failed with error:',
'Error: Missing script: "missing-script"',
'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run',
' in workspace: e',
' at location: {CWD}/test/lib/run-script-workspaces/packages/e',
'Lifecycle script `missing-script` failed with error:',
'Error: Missing script: "missing-script"',
'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run',
' in workspace: noscripts@1.0.0',
' at location: {CWD}/test/lib/run-script-workspaces/packages/noscripts',
], 'should log error msgs for each workspace script')
Expand All @@ -937,11 +937,11 @@ t.test('workspaces', t => {
t.match(RUN_SCRIPTS, [])
t.strictSame(LOG.map(cleanOutput), [
'Lifecycle script `test` failed with error:',
'Error: Missing script: "test"',
'Error: Missing script: "test"\n\nTo see a list of scripts, run:\n npm run',
' in workspace: a@1.0.0',
' at location: {CWD}/test/lib/run-script-workspaces/packages/a',
'Lifecycle script `test` failed with error:',
'Error: Missing script: "test"',
'Error: Missing script: "test"\n\nTo see a list of scripts, run:\n npm run',
' in workspace: b@2.0.0',
' at location: {CWD}/test/lib/run-script-workspaces/packages/b',
], 'should log error msgs for each workspace script')
Expand Down

0 comments on commit 93a061d

Please sign in to comment.