Skip to content

Commit 430623b

Browse files
shreraju-amznShreyas-vgr
authored andcommitted
fix: Changed the evaluateInputHandlers function on Control to throw an error if more than one matching handlers are found
BREAKING CHANGE: Whenever a request is processed by a Control and evaluated with its defined handlers, if more than one handler matches are found, control throws an error with matching handlers.
1 parent a625a09 commit 430623b

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

src/utils/ControlUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ export async function evaluateInputHandlers(control: Control, input: ControlInpu
5353
}
5454

5555
if (matches.length > 1) {
56-
log.error(
57-
`More than one handler matched. Handlers in a single control should be mutually exclusive. ` +
58-
`Defaulting to the first. handlers: ${JSON.stringify(matches.map((x) => x.name))}`,
56+
throw Error(
57+
`More than one handler matched. Handlers in a single control should be mutually exclusive.` +
58+
` handlers: ${JSON.stringify(matches.map((x) => x.name))}`,
5959
);
6060
}
6161

test/scenarios.spec.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -312,31 +312,21 @@ suite('== Custom Handler function scenarios ==', () => {
312312
expect(dateControlState.state.value).eq('2020-01-01');
313313
});
314314

315-
test('Check conflicts in canHandle throws a error log', async () => {
315+
test('Check conflicts in canHandle throws Error', async () => {
316316
const rootControl = new DateSelectorManager().createControlTree();
317317
const input = TestInput.of(
318318
ValueControlIntent.of(AmazonBuiltInSlotType.DATE, {
319319
'AMAZON.DATE': '2018',
320320
action: $.Action.Set,
321321
}),
322322
);
323-
const spy = sinon.stub(DefaultLogger.prototype, 'error');
324-
const result = new ControlResultBuilder(undefined!);
325-
await rootControl.canHandle(input);
326-
await rootControl.handle(input, result);
327-
328-
expect(
329-
spy.calledOnceWith(
330-
'More than one handler matched. Handlers in a single control should be mutually exclusive. Defaulting to the first. handlers: ["SetWithValue (built-in)","SetValue"]',
331-
),
332-
).eq(true);
333-
334-
spy.restore();
335-
336-
const dateControlState = findControlInTreeById(rootControl, 'dateControl');
337-
expect(dateControlState.state.value).eq('2018');
338-
expect(result.acts).length(1);
339-
expect(result.acts[0]).instanceOf(ValueSetAct);
323+
try {
324+
await rootControl.canHandle(input);
325+
} catch (e) {
326+
expect(e.message).eq(
327+
'More than one handler matched. Handlers in a single control should be mutually exclusive. handlers: ["SetWithValue (built-in)","SetValue"]',
328+
);
329+
}
340330
});
341331
});
342332

0 commit comments

Comments
 (0)