Skip to content

Commit

Permalink
[ftr] log async init errors right when they happen (elastic#11898)
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed May 22, 2017
1 parent f3235ba commit 192b2ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
* @return {ProviderCollection}
*/
export function createProviderCollection(lifecycle, log, config) {
return new ProviderCollection([
return new ProviderCollection(log, [
...readProviderSpec('Service', {
// base level services that functional_test_runner exposes
lifecycle: () => lifecycle,
Expand Down
17 changes: 9 additions & 8 deletions src/functional_test_runner/lib/providers/provider_collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { loadTracer } from '../load_tracer';
import { createAsyncInstance, isAsyncInstance } from './async_instance';

export class ProviderCollection {
constructor(providers) {
constructor(log, providers) {
this._log = log;
this._instances = new Map();
this._providers = providers;
}
Expand All @@ -26,7 +27,8 @@ export class ProviderCollection {
}

async loadAll() {
const asyncInitErrors = [];
const asyncInitFailures = [];

await Promise.all(
this._providers.map(async ({ type, name }) => {
try {
Expand All @@ -35,16 +37,15 @@ export class ProviderCollection {
await instance.init();
}
} catch (err) {
asyncInitErrors.push(err);
this._log.warning('Failure loading service %j', name);
this._log.error(err);
asyncInitFailures.push(name);
}
})
);

if (asyncInitErrors.length) {
// just throw the first, it probably caused the others and if not they
// will show up once we fix the first, but creating an AggregateError or
// something seems like overkill
throw asyncInitErrors[0];
if (asyncInitFailures.length) {
throw new Error(`Failure initializing ${asyncInitFailures.length} service(s)`);
}
}

Expand Down

0 comments on commit 192b2ea

Please sign in to comment.