Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve dependency installation error message #5247

Merged
merged 1 commit into from Sep 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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