Skip to content

Commit

Permalink
fix: improve dependency installation error message (#5247)
Browse files Browse the repository at this point in the history
  • Loading branch information
zkochan committed Sep 4, 2022
1 parent b6f788c commit 728c0cd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .changeset/wet-turkeys-allow.md
@@ -0,0 +1,6 @@
---
"@pnpm/default-reporter": patch
"pnpm": patch
---

When an error happens during installation of a subdependency, print some context information in order to be able to locate that subdependency. Print the exact chain of packages that led to the problematic dependency.
12 changes: 4 additions & 8 deletions packages/default-reporter/src/reportError.ts
Expand Up @@ -20,6 +20,9 @@ const colorPath = chalk.gray
export default function reportError (logObj: Log, config?: Config) {
const errorInfo = getErrorInfo(logObj, config)
let output = formatErrorSummary(errorInfo.title, logObj['err']['code'])
if (logObj['pkgsStack']?.length) {
output += `\n\n${formatPkgsStack(logObj['pkgsStack'])}`
}
if (errorInfo.body) {
output += `\n\n${errorInfo.body}`
}
Expand Down Expand Up @@ -67,16 +70,9 @@ function getErrorInfo (logObj: Log, config?: Config): {
if (!err.code?.startsWith?.('ERR_PNPM_')) {
return formatGenericError(err.message ?? logObj['message'], err.stack)
}
const errorOutput = []
if (logObj['pkgsStack']?.length) {
errorOutput.push(formatPkgsStack(logObj['pkgsStack']))
}
if (logObj['hint']) {
errorOutput.push(logObj['hint'] as string)
}
return {
title: err.message ?? '',
body: errorOutput.join(EOL),
body: logObj['hint'],
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions packages/default-reporter/test/reportingErrors.ts
Expand Up @@ -130,6 +130,8 @@ test('prints suggestions when an internet-connection related error happens', (do
next: output => {
expect(output).toBe(`${formatError('ERR_PNPM_BAD_TARBALL_SIZE', 'Actual size (99) of tarball (https://foo) did not match the one specified in \'Content-Length\' header (100)')}
${ERROR_PAD}
${ERROR_PAD}This error happened while installing the dependencies of foo@1.0.0
${ERROR_PAD}
${ERROR_PAD}Seems like you have internet connection issues.
${ERROR_PAD}Try running the same command again.
${ERROR_PAD}If that doesn't help, try one of the following:
Expand All @@ -148,6 +150,13 @@ ${ERROR_PAD}For instance, \`pnpm install --fetch-retries 5 --network-concurrency
})

const err = new PnpmError('BAD_TARBALL_SIZE', 'Actual size (99) of tarball (https://foo) did not match the one specified in \'Content-Length\' header (100)')
err.pkgsStack = [
{
id: 'registry.npmjs.org/foo/1.0.0',
name: 'foo',
version: '1.0.0',
},
]
err['expectedSize'] = 100
err['receivedSize'] = 99
logger.error(err, err)
Expand Down

0 comments on commit 728c0cd

Please sign in to comment.