Skip to content

Commit

Permalink
chore: merge w upstream main
Browse files Browse the repository at this point in the history
  • Loading branch information
zimeg committed Aug 23, 2024
2 parents bba1452 + 36052ef commit 4e1b7ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/App-built-in-middleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,19 @@ describe('App built-in middleware and mechanism', () => {
assert.throws(() => app.event('message.channels', async () => {}), 'Although the document mentions');
assert.throws(() => app.event(/message\..+/, async () => {}), 'Although the document mentions');
});

// https://github.com/slackapi/bolt-js/issues/1457
it('should not cause a runtime exception if the last listener middleware invokes next()', async () => new Promise((resolve, reject) => {
app.event('app_mention', async ({ next }) => {
try {
await next();
resolve();
} catch (e) {
reject(e);
}
});
fakeReceiver.sendEvent(createDummyReceiverEvent('app_mention'));
}));
});

describe('middleware and listener arguments', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ export default class App<AppCustomContext extends StringIndexed = StringIndexed>
// Copy the array so modifications don't affect the original
const listenerMiddleware = [...origListenerMiddleware];

// Don't process the last item in the listenerMiddleware array - it shouldn't get a next fn
// Don't process the last item in the listenerMiddleware array - it will be passed a no-op next fn
const listener = listenerMiddleware.pop();

if (listener === undefined) {
Expand All @@ -1156,13 +1156,13 @@ export default class App<AppCustomContext extends StringIndexed = StringIndexed>
client,
this.logger,
// When all the listener middleware are done processing,
// `listener` here will be called without a `next` execution
// `listener` here will be called with a noop `next` fn
async () => listener({
...(listenerArgs as AnyMiddlewareArgs),
context,
client,
logger: this.logger,
// `next` is already set in the outer processMiddleware
next: () => {},
} as AnyMiddlewareArgs & AllMiddlewareArgs),
);
});
Expand Down

0 comments on commit 4e1b7ed

Please sign in to comment.