From 6abe21c00a2ce0f468b1b3db3173f087bdae2136 Mon Sep 17 00:00:00 2001 From: Ankur Oberoi Date: Wed, 24 Apr 2019 13:29:28 -0700 Subject: [PATCH] fail early when unknown action constraints are used to attach a listener --- src/App.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/App.ts b/src/App.ts index 1982c9e42..0ef18b4bd 100644 --- a/src/App.ts +++ b/src/App.ts @@ -258,6 +258,16 @@ export default class App { (typeof actionIdOrConstraints === 'string' || util.types.isRegExp(actionIdOrConstraints)) ? { action_id: actionIdOrConstraints } : actionIdOrConstraints; + // Fail early if the constraints contain invalid keys + const unknownConstraintKeys = Object.keys(constraints) + .filter(k => (k !== 'action_id' && k !== 'block_id' && k !== 'callback_id')); + if (unknownConstraintKeys.length > 0) { + this.logger.error( + `Action listener cannot be attached using unknown constraint keys: ${unknownConstraintKeys.join(', ')}`, + ); + return; + } + this.listeners.push( [onlyActions, matchConstraints(constraints), ...listeners] as Middleware[], );