From ea32adfa5e834c595a7d480bcd72667836e0aa37 Mon Sep 17 00:00:00 2001 From: neptunian Date: Tue, 12 May 2020 11:54:33 -0400 Subject: [PATCH] log error instead of throw --- .../ingest_manager/server/services/app_context.ts | 7 +++++-- .../services/epm/kibana/index_pattern/install.ts | 10 ++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/ingest_manager/server/services/app_context.ts b/x-pack/plugins/ingest_manager/server/services/app_context.ts index e5bc082f6f0fc..91b09d651bf5c 100644 --- a/x-pack/plugins/ingest_manager/server/services/app_context.ts +++ b/x-pack/plugins/ingest_manager/server/services/app_context.ts @@ -21,7 +21,7 @@ class AppContextService { private isProductionMode: boolean = false; private kibanaVersion: string | undefined; private cloud?: CloudSetup; - private logger?: Logger; + private logger: Logger | undefined; private httpSetup?: HttpServiceSetup; public async start(appContext: IngestManagerAppContext) { @@ -53,7 +53,7 @@ class AppContextService { public getSecurity() { if (!this.security) { - throw new Error('Secury service not set.'); + throw new Error('Security service not set.'); } return this.security; } @@ -63,6 +63,9 @@ class AppContextService { } public getLogger() { + if (!this.logger) { + throw new Error('Logger not set.'); + } return this.logger; } diff --git a/x-pack/plugins/ingest_manager/server/services/epm/kibana/index_pattern/install.ts b/x-pack/plugins/ingest_manager/server/services/epm/kibana/index_pattern/install.ts index 6cdcb8782f38e..d220ecfc62bb8 100644 --- a/x-pack/plugins/ingest_manager/server/services/epm/kibana/index_pattern/install.ts +++ b/x-pack/plugins/ingest_manager/server/services/epm/kibana/index_pattern/install.ts @@ -13,6 +13,7 @@ import * as Registry from '../../registry'; import { loadFieldsFromYaml, Fields, Field } from '../../fields/field'; import { getPackageKeysByStatus } from '../../packages/get'; import { InstallationStatus, RegistryPackage, CallESAsCurrentUser } from '../../../../types'; +import { appContextService } from '../../../../services'; interface FieldFormatMap { [key: string]: FieldFormatMapItem; @@ -366,10 +367,11 @@ const getFieldFormatParams = (field: Field): FieldFormatParams => { return params; }; -export const ensureDefaultIndices = async (callCluster: CallESAsCurrentUser) => +export const ensureDefaultIndices = async (callCluster: CallESAsCurrentUser) => { // create placeholder indices to supress errors in the kibana Dashboards app // that no matching indices exist https://github.com/elastic/kibana/issues/62343 - Promise.all( + const logger = appContextService.getLogger(); + return Promise.all( Object.keys(IndexPatternType).map(async indexPattern => { const defaultIndexPatternName = indexPattern + INDEX_PATTERN_PLACEHOLDER_SUFFIX; const indexExists = await callCluster('indices.exists', { index: defaultIndexPatternName }); @@ -386,9 +388,9 @@ export const ensureDefaultIndices = async (callCluster: CallESAsCurrentUser) => }, }); } catch (putErr) { - // throw new Error(`${defaultIndexPatternName} could not be created`); - throw new Error(putErr); + logger.error(`${defaultIndexPatternName} could not be created`); } } }) ); +};