Skip to content

Commit

Permalink
Don't mutate error message (elastic#58452)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
streamich and elasticmachine authored Feb 25, 2020
1 parent afb5d8f commit db05fb6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/plugins/expressions/common/execution/execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/expressions/common/execution/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit db05fb6

Please sign in to comment.