Skip to content

Commit fb61847

Browse files
committed
Mark timefield error as user error
1 parent 9f6eb0a commit fb61847

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

x-pack/platform/plugins/shared/stack_alerts/server/rule_types/es_query/lib/fetch_search_source_query.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,27 @@ describe('fetchSearchSourceQuery', () => {
659659
}
660660
});
661661

662+
it('should throw user error if data view does not have a timefield', async () => {
663+
try {
664+
const dataView = createDataView();
665+
dataView.timeFieldName = undefined;
666+
const searchSourceInstance = createSearchSourceMock({ index: dataView });
667+
668+
await updateSearchSource(
669+
searchSourceInstance,
670+
dataView,
671+
defaultParams,
672+
'2020-01-09T22:12:41.941Z',
673+
new Date().toISOString(),
674+
new Date().toISOString(),
675+
logger
676+
);
677+
} catch (err) {
678+
expect(getErrorSource(err)).toBe(TaskErrorSource.USER);
679+
expect(err.message).toBe('Data view with ID test-id no longer contains a time field.');
680+
}
681+
});
682+
662683
it('should re-throw error for generic errors', async () => {
663684
searchSourceCommonMock.createLazy.mockImplementationOnce(() => {
664685
throw new Error('fail');

x-pack/platform/plugins/shared/stack_alerts/server/rule_types/es_query/lib/fetch_search_source_query.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ export async function updateSearchSource(
140140
const timeField = await index.getTimeField();
141141

142142
if (!timeField) {
143-
throw new Error(`Data view with ID ${index.id} no longer contains a time field.`);
143+
throw createTaskRunError(
144+
new Error(`Data view with ID ${index.id} no longer contains a time field.`),
145+
TaskErrorSource.USER
146+
);
144147
}
145148

146149
searchSource.setField('size', isGroupAgg ? 0 : params.size);

0 commit comments

Comments
 (0)