Skip to content

Commit

Permalink
fix: report correct errors when using the pnpm server (#7032)
Browse files Browse the repository at this point in the history
  • Loading branch information
gluxon committed Sep 2, 2023
1 parent d1bd587 commit cc785f7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/wet-lies-smoke.md
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 9 additions & 1 deletion cli/default-reporter/src/reportError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'])}`
Expand All @@ -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): {
Expand Down

0 comments on commit cc785f7

Please sign in to comment.