From 14974d8029b645b618bbd6cf86b4ae04f4368769 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Wed, 2 Nov 2022 10:36:42 +0200 Subject: [PATCH] fix: cannot set property name of which has only a getter (#5574) close #5572 --- .changeset/wet-hornets-cheat.md | 5 +++++ packages/pnpm/src/err.ts | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/wet-hornets-cheat.md diff --git a/.changeset/wet-hornets-cheat.md b/.changeset/wet-hornets-cheat.md new file mode 100644 index 00000000000..ebc5328fd55 --- /dev/null +++ b/.changeset/wet-hornets-cheat.md @@ -0,0 +1,5 @@ +--- +"pnpm": patch +--- + +Don't fail if cannot override the name field of the error object [#5572](https://github.com/pnpm/pnpm/issues/5572). diff --git a/packages/pnpm/src/err.ts b/packages/pnpm/src/err.ts index 40ac049eff9..c12b7f25aa5 100644 --- a/packages/pnpm/src/err.ts +++ b/packages/pnpm/src/err.ts @@ -11,7 +11,11 @@ export function errorHandler (error: Error) { return } if (error.name != null && error.name !== 'pnpm' && !error.name.startsWith('pnpm:')) { - error.name = 'pnpm' + try { + error.name = 'pnpm' + } catch { + // Sometimes the name property is read-only + } } // bole passes only the name, message and stack of an error