mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
fix: improve dependency installation error message (#5247)
This commit is contained in:
6
.changeset/wet-turkeys-allow.md
Normal file
6
.changeset/wet-turkeys-allow.md
Normal file
@@ -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.
|
||||
@@ -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}`
|
||||
}
|
||||
@@ -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'],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user