Skip to content

Commit

Permalink
Fix error handling that caused functional test failures.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeelmers committed Nov 9, 2020
1 parent b70e97d commit d4d93af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/plugins/data/common/search/aggs/agg_configs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ describe('AggConfigs', () => {
type: 'oops',
params: {},
})
).toThrowErrorMatchingInlineSnapshot(`"Unable to find a registered agg type for \\"oops\\""`);
).toThrowErrorMatchingInlineSnapshot(
`"Unable to find a registered agg type for \\"oops\\"."`
);
});
});

Expand Down
28 changes: 17 additions & 11 deletions src/plugins/data/common/search/aggs/agg_configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,30 @@ export class AggConfigs {
{ addToAggConfigs = true } = {}
) => {
const { type } = params;
const aggType = typeof type === 'string' ? this.typesRegistry.get(type) : type;
const getType = (t: string) => {
const typeFromRegistry = this.typesRegistry.get(t);

if (!typeFromRegistry) {
throw new Error(
i18n.translate('data.search.aggs.error.aggNotFound', {
defaultMessage: 'Unable to find a registered agg type for "{type}".',
values: { type: type as string },
})
);
}

if (!aggType) {
throw new Error(
i18n.translate('data.search.aggs.error.aggNotFound', {
defaultMessage: 'Unable to find a registered agg type for "{type}"',
values: { type: type as string },
})
);
}
return typeFromRegistry;
};

let aggConfig;

if (params instanceof AggConfig) {
aggConfig = params;
params.parent = this;
} else {
aggConfig = new AggConfig(this, { ...params, type: aggType });
aggConfig = new AggConfig(this, {
...params,
type: typeof type === 'string' ? getType(type) : type,
});
}

if (addToAggConfigs) {
Expand Down

0 comments on commit d4d93af

Please sign in to comment.