Skip to content

Commit

Permalink
fix(errors): better error output
Browse files Browse the repository at this point in the history
- Remove `FatalError` since it was not really helping
- Upon pack or install error, verbose mode will dump the entire nested error structure
- Use canned error msgs for the two event listeners, since the real ones get thrown immediately after the `emit()`, then we catch them in the command handler
- Retrieves error summaries from npm output, if available (is there a yarn analogue?)
- Closes #338
  • Loading branch information
boneskull committed Aug 30, 2023
1 parent 4afd125 commit 51b0002
Show file tree
Hide file tree
Showing 12 changed files with 464 additions and 65 deletions.
172 changes: 172 additions & 0 deletions __snapshots__/cli.spec.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,175 @@ exports['midnight-smoker smoker CLI check when a check fails when the rule sever
✔ Successfully ran 3 checks
✔ Lovey-dovey! 💖
`

exports['midnight-smoker smoker CLI when packing fails should provide a reason [snapshot] 1'] = `
💨 midnight-smoker v<version>
- Packing current project…
✖ Failed while packing!
Package manager "npm" failed to pack:
Invalid package, must have name and version
(use --verbose for more details)
`

exports['midnight-smoker smoker CLI when packing fails when in verbose mode should provide more detail [snapshot] 1'] = `
💨 midnight-smoker v<version>
- Packing current project…
✖ Failed while packing!
PackError: Package manager "npm" failed to pack:
Invalid package, must have name and version
at Npm7.pack (<path/to/file>:<line>:<col>)
at processTicksAndRejections (<path/to/file>:<line>:<col>)
at Smoker.pack (<path/to/file>:<line>:<col>)
at Smoker.smoke (<path/to/file>:<line>:<col>)
at Object.handler (<path/to/file>:<line>:<col>) {
code: 'ESMOKER_PACK',
[cause]: {
pm: 'npm',
error: Error: Command failed with exit code 1: <path/to/>/bin/node <path/to/>/.bin/corepack npm@<version> pack --json --pack-destination=<path/to/dir> --foreground-scripts=false
npm ERR! Invalid package, must have name and version
npm ERR! A complete log of this run can be found in: <path/to/some>.log
{
"error": {
"code": null,
"summary": "Invalid package, must have name and version",
"detail": ""
}
}
at makeError (<path/to/file>:<line>:<col>)
at handlePromise (<path/to/file>:<line>:<col>)
at processTicksAndRejections (<path/to/file>:<line>:<col>)
at CorepackExecutor.exec (<path/to/file>:<line>:<col>)
at Npm7.pack (<path/to/file>:<line>:<col>)
at Smoker.pack (<path/to/file>:<line>:<col>)
at Smoker.smoke (<path/to/file>:<line>:<col>)
at Object.handler (<path/to/file>:<line>:<col>) {
shortMessage: 'Command failed with exit code 1: <path/to/>/bin/node <path/to/>/.bin/corepack npm@<version> pack --json --pack-destination=<path/to/dir> --foreground-scripts=false',
command: <path/to/>/bin/node <path/to/>/.bin/corepack npm@<version> pack --json --pack-destination=<path/to/dir> --foreground-scripts=false',
escapedCommand: '"<path/to/>/bin/node" "<path/to/>/.bin/corepack" "npm@<version>" pack --json "--pack-destination=<path/to/dir> "--foreground-scripts=false"',
exitCode: 1,
signal: undefined,
signalDescription: undefined,
stdout: '{\\n' +
' "error": {\\n' +
' "code": null,\\n' +
' "summary": "Invalid package, must have name and version",\\n' +
' "detail": ""\\n' +
' }\\n' +
'}',
stderr: 'npm ERR! Invalid package, must have name and version\\n' +
'\\n' +
'npm ERR! A complete log of this run can be found in: <path/to/some>.log',
failed: true,
timedOut: false,
isCanceled: false,
killed: false
},
output: 'npm ERR! Invalid package, must have name and version\\n' +
'\\n' +
'npm ERR! A complete log of this run can be found in: <path/to/some>.log'
}
}
`

exports['midnight-smoker smoker CLI when installation fails should provide a reason [snapshot] 1'] = `
💨 midnight-smoker v<version>
- Packing current project…
✔ Packed 1 unique package using npm@<version>…
- Installing 1 unique package from tarball using npm@<version>…
✖ Failed while installing!
Package manager "npm" failed to install packages
(use --verbose for more details)
`

exports['midnight-smoker smoker CLI when installation fails when in verbose mode should provide more detail [snapshot] 1'] = `
💨 midnight-smoker v<version>
- Packing current project…
✔ Packed 1 unique package using npm@<version>…
- Installing 1 unique package from tarball using npm@<version>…
✖ Failed while installing!
InstallError: Package manager "npm" failed to install packages
at Npm7.install (<path/to/file>:<line>:<col>)
at processTicksAndRejections (<path/to/file>:<line>:<col>)
at Smoker.install (<path/to/file>:<line>:<col>)
at Smoker.smoke (<path/to/file>:<line>:<col>)
at Object.handler (<path/to/file>:<line>:<col>) {
code: 'ESMOKER_INSTALL',
[cause]: {
pm: 'npm',
error: Error: Command failed with exit code 1: <path/to/>/bin/node <path/to/>/.bin/corepack npm@<version> install --no-package-lock --global-style <path/to/some>.tgz
npm WARN config global-style This option has been deprecated in favor of \`--install-strategy=shallow\`
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: undefined@undefined
npm ERR! Found: install-error@1.0.0
npm ERR! node_modules/install-error
npm ERR! <path/to/some>.tgz" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer install-error@"2.0.0" from install-error@1.0.0
npm ERR! node_modules/install-error
npm ERR! <path/to/some>.tgz" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR!
npm ERR! For a full report see:
npm ERR! <path/to/some>.txt
npm ERR! A complete log of this run can be found in: <path/to/some>.log
at makeError (<path/to/file>:<line>:<col>)
at handlePromise (<path/to/file>:<line>:<col>)
at processTicksAndRejections (<path/to/file>:<line>:<col>)
at CorepackExecutor.exec (<path/to/file>:<line>:<col>)
at Npm7.install (<path/to/file>:<line>:<col>)
at Smoker.install (<path/to/file>:<line>:<col>)
at Smoker.smoke (<path/to/file>:<line>:<col>)
at Object.handler (<path/to/file>:<line>:<col>) {
shortMessage: 'Command failed with exit code 1: <path/to/>/bin/node <path/to/>/.bin/corepack npm@<version> install --no-package-lock --global-style <path/to/some>.tgz',
command: <path/to/>/bin/node <path/to/>/.bin/corepack npm@<version> install --no-package-lock --global-style <path/to/some>.tgz',
escapedCommand: '"<path/to/>/bin/node" "<path/to/>/.bin/corepack" "npm@<version>" install --no-package-lock --global-style <path/to/some>.tgz"',
exitCode: 1,
signal: undefined,
signalDescription: undefined,
stdout: '',
stderr: 'npm WARN config global-style This option has been deprecated in favor of \`--install-strategy=shallow\`\\n' +
'npm ERR! code ERESOLVE\\n' +
'npm ERR! ERESOLVE unable to resolve dependency tree\\n' +
'npm ERR! \\n' +
'npm ERR! While resolving: undefined@undefined\\n' +
'npm ERR! Found: install-error@1.0.0\\n' +
'npm ERR! node_modules/install-error\\n' +
'npm ERR! <path/to/some>.tgz" from the root project\\n' +
'npm ERR! \\n' +
'npm ERR! Could not resolve dependency:\\n' +
'npm ERR! peer install-error@"2.0.0" from install-error@1.0.0\\n' +
'npm ERR! node_modules/install-error\\n' +
'npm ERR! <path/to/some>.tgz" from the root project\\n' +
'npm ERR! \\n' +
'npm ERR! Fix the upstream dependency conflict, or retry\\n' +
'npm ERR! this command with --force or --legacy-peer-deps\\n' +
'npm ERR! to accept an incorrect (and potentially broken) dependency resolution.\\n' +
'npm ERR! \\n' +
'npm ERR! \\n' +
'npm ERR! For a full report see:\\n' +
'npm ERR! <path/to/some>.txt\\n' +
'\\n' +
'npm ERR! A complete log of this run can be found in: <path/to/some>.log',
failed: true,
timedOut: false,
isCanceled: false,
killed: false
}
}
}
`
121 changes: 95 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
"rewiremock": "3.14.5",
"sinon": "15.2.0",
"snap-shot-it": "7.9.10",
"strip-ansi": "5.2.0",
"ts-node": "10.9.1",
"typescript": "5.2.2",
"unexpected": "13.2.1",
Expand Down
Loading

0 comments on commit 51b0002

Please sign in to comment.