From e4634c49832ffae2b4179104abd0e155fa16b17a Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 25 Feb 2020 11:11:02 +0100 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=F0=9F=90=9B=20don't=20mutate=20erro?= =?UTF-8?q?r=20object=20in-place?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This avoids mutating error thrown by an expression function in-place. The error might not even be an object, in which case mutating it will throw. --- src/plugins/expressions/common/execution/execution.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/expressions/common/execution/execution.ts b/src/plugins/expressions/common/execution/execution.ts index 7e7df822724ae..272448870e817 100644 --- a/src/plugins/expressions/common/execution/execution.ts +++ b/src/plugins/expressions/common/execution/execution.ts @@ -230,8 +230,8 @@ export class Execution< input = output; } catch (rawError) { const timeEnd: number = this.params.debug ? performance.now() : 0; - rawError.message = `[${fnName}] > ${rawError.message}`; const error = createError(rawError) as ExpressionValueError; + error.error.message = `[${fnName}] > ${error.error.message}`; if (this.params.debug) { (link as ExpressionAstFunction).debug = { From eb4f516d9064732f2a4c3e17bdbaa40f8a757a9a Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 25 Feb 2020 11:13:34 +0100 Subject: [PATCH 2/2] =?UTF-8?q?test:=20=F0=9F=92=8D=20capture=20in=20test?= =?UTF-8?q?=20that=20thrown=20error=20is=20not=20mutated?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/expressions/common/execution/execution.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/expressions/common/execution/execution.test.ts b/src/plugins/expressions/common/execution/execution.test.ts index f6ff9efca848b..4776204a8ab2f 100644 --- a/src/plugins/expressions/common/execution/execution.test.ts +++ b/src/plugins/expressions/common/execution/execution.test.ts @@ -630,6 +630,7 @@ describe('Execution', () => { }, }); expect(node2.debug?.rawError).toBeInstanceOf(Error); + expect(node2.debug?.rawError).toEqual(new Error('foo')); }); test('sets .debug object to expected shape', async () => {