fix: report correct errors when using the pnpm server (#7032)

This commit is contained in:
Brandon Cheng
2023-09-02 15:28:59 -04:00
committed by GitHub
parent d1bd5871c3
commit cc785f7e19
2 changed files with 15 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/default-reporter": patch
pnpm: patch
---
Fix a bug causing errors to be printed as `Cannot read properties of undefined (reading 'code')` instead of the underlying reason when using the pnpm store server.

View File

@@ -21,7 +21,7 @@ const colorPath = chalk.gray
export function reportError (logObj: Log, config?: Config) {
const errorInfo = getErrorInfo(logObj, config)
let output = formatErrorSummary(errorInfo.title, logObj['err']['code'])
let output = formatErrorSummary(errorInfo.title, (logObj as LogObjWithPossibleError).err?.code)
if (logObj['pkgsStack'] != null) {
if (logObj['pkgsStack'].length > 0) {
output += `\n\n${formatPkgsStack(logObj['pkgsStack'])}`
@@ -33,6 +33,14 @@ export function reportError (logObj: Log, config?: Config) {
output += `\n\n${errorInfo.body}`
}
return output
/**
* A type to assist with introspection of the logObj.
* These objects may or may not have an `err` field.
*/
interface LogObjWithPossibleError {
readonly err?: { code?: string }
}
}
function getErrorInfo (logObj: Log, config?: Config): {