From f61de1db99c0b4ba86f1fef2e8517d85d24af689 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 346a15a4996..4cca3edb2e8 100644 --- a/packages/pnpm/src/err.ts +++ b/packages/pnpm/src/err.ts @@ -11,7 +11,11 @@ export default function err (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