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

This commit is contained in:
Brandon Cheng authored and GitHub committed 2023-09-02 22:28:59 +03:00
1 parent d1bd5871c3
commit cc785f7e19
2 files changed
+15 -1

No files matched your search

+6
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.
+9 -1
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): {