Skip to content

Commit

Permalink
log error instead of throw (#66254) (#66341)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
neptunian and elasticmachine authored May 13, 2020
1 parent ba404ac commit 165abca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 5 additions & 2 deletions x-pack/plugins/ingest_manager/server/services/app_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -63,6 +63,9 @@ class AppContextService {
}

public getLogger() {
if (!this.logger) {
throw new Error('Logger not set.');
}
return this.logger;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 });
Expand All @@ -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`);
}
}
})
);
};

0 comments on commit 165abca

Please sign in to comment.