From 1fe4135ab6ebe039174bb9be2073241867213a2a Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Wed, 14 Jul 2021 12:18:21 +0200 Subject: [PATCH] [Discover][Main] Fix missing error message when building search query throws exceptions (#103923) * Fix missing error message when building search fails * Fix test * Update _date_nested.ts * Lint config.js Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../apps/main/services/use_saved_search.ts | 10 +++++- test/functional/apps/discover/_date_nested.ts | 35 +++++++++++++++++++ test/functional/apps/discover/index.ts | 1 + test/functional/config.js | 15 ++++++++ .../es_archiver/date_nested/data.json | 30 ++++++++++++++++ .../es_archiver/date_nested/mappings.json | 22 ++++++++++++ 6 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 test/functional/apps/discover/_date_nested.ts create mode 100644 test/functional/fixtures/es_archiver/date_nested/data.json create mode 100644 test/functional/fixtures/es_archiver/date_nested/mappings.json diff --git a/src/plugins/discover/public/application/apps/main/services/use_saved_search.ts b/src/plugins/discover/public/application/apps/main/services/use_saved_search.ts index 8c847b54078eb7..b449d35dca9ad6 100644 --- a/src/plugins/discover/public/application/apps/main/services/use_saved_search.ts +++ b/src/plugins/discover/public/application/apps/main/services/use_saved_search.ts @@ -279,13 +279,21 @@ export const useSavedSearch = ({ ).pipe(debounceTime(100)); const subscription = fetch$.subscribe((val) => { - fetchAll(val === 'reset'); + try { + fetchAll(val === 'reset'); + } catch (error) { + data$.next({ + state: FetchStatus.ERROR, + fetchError: error, + }); + } }); return () => { subscription.unsubscribe(); }; }, [ + data$, data.query.queryString, filterManager, refetch$, diff --git a/test/functional/apps/discover/_date_nested.ts b/test/functional/apps/discover/_date_nested.ts new file mode 100644 index 00000000000000..8297d84832ff64 --- /dev/null +++ b/test/functional/apps/discover/_date_nested.ts @@ -0,0 +1,35 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { FtrProviderContext } from '../../ftr_provider_context'; + +export default function ({ getService, getPageObjects }: FtrProviderContext) { + const esArchiver = getService('esArchiver'); + const testSubjects = getService('testSubjects'); + const PageObjects = getPageObjects(['common', 'timePicker', 'discover']); + const security = getService('security'); + + describe('timefield is a date in a nested field', function () { + before(async function () { + await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/date_nested'); + await security.testUser.setRoles(['kibana_admin', 'kibana_date_nested']); + await PageObjects.common.navigateToApp('discover'); + }); + + after(async function unloadMakelogs() { + await security.testUser.restoreDefaults(); + await esArchiver.unload('test/functional/fixtures/es_archiver/date_nested'); + }); + + it('should show an error message', async function () { + await PageObjects.discover.selectIndexPattern('date-nested'); + await PageObjects.discover.waitUntilSearchingHasFinished(); + await testSubjects.existOrFail('discoverNoResultsError'); + }); + }); +} diff --git a/test/functional/apps/discover/index.ts b/test/functional/apps/discover/index.ts index a17bf53e7f4781..ac8aa50085f33a 100644 --- a/test/functional/apps/discover/index.ts +++ b/test/functional/apps/discover/index.ts @@ -51,5 +51,6 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) { loadTestFile(require.resolve('./_indexpattern_with_unmapped_fields')); loadTestFile(require.resolve('./_runtime_fields_editor')); loadTestFile(require.resolve('./_huge_fields')); + loadTestFile(require.resolve('./_date_nested')); }); } diff --git a/test/functional/config.js b/test/functional/config.js index c2c856517c58e4..1c0c519f21e4c8 100644 --- a/test/functional/config.js +++ b/test/functional/config.js @@ -247,6 +247,21 @@ export default async function ({ readConfigFile }) { }, kibana: [], }, + + kibana_date_nested: { + elasticsearch: { + cluster: [], + indices: [ + { + names: ['date-nested'], + privileges: ['read', 'view_index_metadata'], + field_security: { grant: ['*'], except: [] }, + }, + ], + run_as: [], + }, + kibana: [], + }, kibana_message_with_newline: { elasticsearch: { cluster: [], diff --git a/test/functional/fixtures/es_archiver/date_nested/data.json b/test/functional/fixtures/es_archiver/date_nested/data.json new file mode 100644 index 00000000000000..0bdb3fc510a63a --- /dev/null +++ b/test/functional/fixtures/es_archiver/date_nested/data.json @@ -0,0 +1,30 @@ +{ + "type": "doc", + "value": { + "id": "index-pattern:date-nested", + "index": ".kibana", + "source": { + "index-pattern": { + "fields":"[]", + "timeFieldName": "@timestamp", + "title": "date-nested" + }, + "type": "index-pattern" + } + } +} + + +{ + "type": "doc", + "value": { + "id": "date-nested-1", + "index": "date-nested", + "source": { + "message" : "test", + "nested": { + "timestamp": "2021-06-30T12:00:00.123Z" + } + } + } +} diff --git a/test/functional/fixtures/es_archiver/date_nested/mappings.json b/test/functional/fixtures/es_archiver/date_nested/mappings.json new file mode 100644 index 00000000000000..f30e5863f4f8b8 --- /dev/null +++ b/test/functional/fixtures/es_archiver/date_nested/mappings.json @@ -0,0 +1,22 @@ +{ + "type": "index", + "value": { + "index": "date-nested", + "mappings": { + "properties": { + "message": { + "type": "text" + }, + "nested": { + "type": "nested" + } + } + }, + "settings": { + "index": { + "number_of_replicas": "0", + "number_of_shards": "1" + } + } + } +}