From 728c0cdf67079c022c73bcc10565c596f07ac5ad Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Mon, 5 Sep 2022 00:40:47 +0300 Subject: [PATCH] fix: improve dependency installation error message (#5247) --- .changeset/wet-turkeys-allow.md | 6 ++++++ packages/default-reporter/src/reportError.ts | 12 ++++-------- packages/default-reporter/test/reportingErrors.ts | 9 +++++++++ 3 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 .changeset/wet-turkeys-allow.md diff --git a/.changeset/wet-turkeys-allow.md b/.changeset/wet-turkeys-allow.md new file mode 100644 index 00000000000..05acb0ed032 --- /dev/null +++ b/.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. diff --git a/packages/default-reporter/src/reportError.ts b/packages/default-reporter/src/reportError.ts index 120b410ace9..d08de9bda41 100644 --- a/packages/default-reporter/src/reportError.ts +++ b/packages/default-reporter/src/reportError.ts @@ -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'], } } } diff --git a/packages/default-reporter/test/reportingErrors.ts b/packages/default-reporter/test/reportingErrors.ts index f5e51c11d4c..bd7e0872585 100644 --- a/packages/default-reporter/test/reportingErrors.ts +++ b/packages/default-reporter/test/reportingErrors.ts @@ -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)