Skip to content

Commit

Permalink
Log the errors reported by addLastRunError to the console (#179962)
Browse files Browse the repository at this point in the history
Fixes: #179924

## To verify

Please follow the steps in the issue to reproduce.
  • Loading branch information
ersin-erdal authored Apr 5, 2024
1 parent be980df commit e5adbbd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3333,7 +3333,13 @@ describe('Task Runner', () => {
});

expect(getErrorSource(runnerResult.taskRunError as Error)).toBe(TaskErrorSource.FRAMEWORK);
expect(runnerResult.taskRunError).toEqual(new Error('an error occurred,second error occurred'));
expect(runnerResult.taskRunError?.message).toBe(
'Executing Rule test:1 has resulted in the following error(s): an error occurred,second error occurred'
);
expect(logger.error).toHaveBeenCalledWith(
'Executing Rule test:1 has resulted in the following error(s): an error occurred,second error occurred',
{ tags: ['test', '1', 'rule-run-failed'] }
);
});

test('returns user error if all the errors are user error', async () => {
Expand Down
9 changes: 8 additions & 1 deletion x-pack/plugins/alerting/server/task_runner/task_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,9 +716,16 @@ export class TaskRunner<
const { errors: errorsFromLastRun } = this.ruleResult.getLastRunResults();
if (errorsFromLastRun.length > 0) {
const isUserError = !errorsFromLastRun.some((lastRunError) => !lastRunError.userError);
const lasRunErrorMessages = errorsFromLastRun
.map((lastRunError) => lastRunError.message)
.join(',');
const errorMessage = `Executing Rule ${this.ruleType.id}:${ruleId} has resulted in the following error(s): ${lasRunErrorMessages}`;
this.logger.error(errorMessage, {
tags: [this.ruleType.id, ruleId, 'rule-run-failed'],
});
return {
taskRunError: createTaskRunError(
new Error(errorsFromLastRun.map((lastRunError) => lastRunError.message).join(',')),
new Error(errorMessage),
isUserError ? TaskErrorSource.USER : TaskErrorSource.FRAMEWORK
),
};
Expand Down

0 comments on commit e5adbbd

Please sign in to comment.