Don't mutate error message (#58452)

* fix: 🐛 don't mutate error object in-place

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.

* test: 💍 capture in test that thrown error is not mutated

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Vadim Dalecky 2020-02-25 15:00:28 +01:00 committed by GitHub
parent afb5d8fa58
commit db05fb6738
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 1 deletions

View file

@ -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 () => {

View file

@ -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 = {