File tree Expand file tree Collapse file tree 4 files changed +17
-15
lines changed
apps/test-bot/src/app/commands/(general) Expand file tree Collapse file tree 4 files changed +17
-15
lines changed Original file line number Diff line number Diff line change 11import { Logger , type MiddlewareContext , stopMiddlewares } from 'commandkit' ;
22
33export function beforeExecute ( ctx : MiddlewareContext ) {
4- Logger . info ( `Command-scoped middleware: ${ ctx . commandName } will be stopped!` ) ;
54 Logger . info (
6- 'None of the other beforeExecute middlewares are supposed to be executed' ,
5+ `Command-scoped middleware: ${ ctx . commandName } will be executed!` ,
76 ) ;
7+
8+ // Logger.info(`Command-scoped middleware: ${ctx.commandName} will be stopped!`);
9+ // Logger.info(
10+ // 'None of the other beforeExecute middlewares are supposed to be executed',
11+ // );
812 // stopMiddlewares();
913}
1014
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import {
1212 CommandMetadata ,
1313 MessageCommandContext ,
1414 stopMiddlewares ,
15+ Logger ,
1516} from 'commandkit' ;
1617
1718export const command : CommandData = {
@@ -66,6 +67,9 @@ export async function chatInput({
6667 interaction,
6768 client,
6869} : ChatInputCommandContext ) {
70+ Logger . debug ( 'calling stopMiddlewares' ) ;
71+ stopMiddlewares ( ) ;
72+
6973 if ( ! interaction . channel ) return ;
7074
7175 const button = new ButtonKit ( )
@@ -99,6 +103,4 @@ export async function chatInput({
99103 button . setDisabled ( true ) ;
100104 message . edit ( { components : [ row ] } ) ;
101105 } ) ;
102-
103- stopMiddlewares ( ) ;
104106}
Original file line number Diff line number Diff line change @@ -230,26 +230,19 @@ export class AppCommandRunner {
230230 Logger . debug (
231231 `Middleware propagation stopped for command "${ middlewareCtx . commandName } ". stopMiddlewares() was called by the command itself` ,
232232 ) ;
233- }
234-
235- if (
236- ! isErrorType ( e , [
237- CommandKitErrorCodes . ForwardedCommand ,
238- CommandKitErrorCodes . StopMiddlewares ,
239- ] )
240- ) {
233+ } else if ( ! isErrorType ( e , CommandKitErrorCodes . ForwardedCommand ) ) {
241234 if ( shouldThrowOnError ) {
242235 throw e ;
243236 }
244-
245237 Logger . error ( e ) ;
246238 }
247239 }
248240 }
249241 } else {
250242 result = {
251243 error : true ,
252- message : 'Command execution was cancelled by the middleware.' ,
244+ message :
245+ 'Command execution was cancelled by a beforeExecute middleware.' ,
253246 } ;
254247 }
255248
@@ -258,7 +251,7 @@ export class AppCommandRunner {
258251 ) ;
259252
260253 // Run middleware after command execution only if `stopMiddlewares()` wasn't
261- // called in either `beforeExecute` middleware or in the command itself
254+ // called in either `beforeExecute` middleware or in the command itself.
262255 if (
263256 ! beforeMiddlewaresStopped &&
264257 ! stopMiddlewaresCalledInCmd &&
Original file line number Diff line number Diff line change @@ -70,6 +70,9 @@ export function makeContextAwareFunction<
7070 } catch ( e ) {
7171 if ( ! isCommandKitError ( e ) ) {
7272 env . setExecutionError ( e as Error ) ;
73+ } else {
74+ // rethrow commandkit errors so they can be handled by the caller
75+ throw e ;
7376 }
7477 } finally {
7578 if ( typeof finalizer === 'function' ) {
You can’t perform that action at this time.
0 commit comments