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 1
1
import { Logger , type MiddlewareContext , stopMiddlewares } from 'commandkit' ;
2
2
3
3
export function beforeExecute ( ctx : MiddlewareContext ) {
4
- Logger . info ( `Command-scoped middleware: ${ ctx . commandName } will be stopped!` ) ;
5
4
Logger . info (
6
- 'None of the other beforeExecute middlewares are supposed to be executed' ,
5
+ `Command-scoped middleware: ${ ctx . commandName } will be executed!` ,
7
6
) ;
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
+ // );
8
12
// stopMiddlewares();
9
13
}
10
14
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import {
12
12
CommandMetadata ,
13
13
MessageCommandContext ,
14
14
stopMiddlewares ,
15
+ Logger ,
15
16
} from 'commandkit' ;
16
17
17
18
export const command : CommandData = {
@@ -66,6 +67,9 @@ export async function chatInput({
66
67
interaction,
67
68
client,
68
69
} : ChatInputCommandContext ) {
70
+ Logger . debug ( 'calling stopMiddlewares' ) ;
71
+ stopMiddlewares ( ) ;
72
+
69
73
if ( ! interaction . channel ) return ;
70
74
71
75
const button = new ButtonKit ( )
@@ -99,6 +103,4 @@ export async function chatInput({
99
103
button . setDisabled ( true ) ;
100
104
message . edit ( { components : [ row ] } ) ;
101
105
} ) ;
102
-
103
- stopMiddlewares ( ) ;
104
106
}
Original file line number Diff line number Diff line change @@ -230,26 +230,19 @@ export class AppCommandRunner {
230
230
Logger . debug (
231
231
`Middleware propagation stopped for command "${ middlewareCtx . commandName } ". stopMiddlewares() was called by the command itself` ,
232
232
) ;
233
- }
234
-
235
- if (
236
- ! isErrorType ( e , [
237
- CommandKitErrorCodes . ForwardedCommand ,
238
- CommandKitErrorCodes . StopMiddlewares ,
239
- ] )
240
- ) {
233
+ } else if ( ! isErrorType ( e , CommandKitErrorCodes . ForwardedCommand ) ) {
241
234
if ( shouldThrowOnError ) {
242
235
throw e ;
243
236
}
244
-
245
237
Logger . error ( e ) ;
246
238
}
247
239
}
248
240
}
249
241
} else {
250
242
result = {
251
243
error : true ,
252
- message : 'Command execution was cancelled by the middleware.' ,
244
+ message :
245
+ 'Command execution was cancelled by a beforeExecute middleware.' ,
253
246
} ;
254
247
}
255
248
@@ -258,7 +251,7 @@ export class AppCommandRunner {
258
251
) ;
259
252
260
253
// 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.
262
255
if (
263
256
! beforeMiddlewaresStopped &&
264
257
! stopMiddlewaresCalledInCmd &&
Original file line number Diff line number Diff line change @@ -70,6 +70,9 @@ export function makeContextAwareFunction<
70
70
} catch ( e ) {
71
71
if ( ! isCommandKitError ( e ) ) {
72
72
env . setExecutionError ( e as Error ) ;
73
+ } else {
74
+ // rethrow commandkit errors so they can be handled by the caller
75
+ throw e ;
73
76
}
74
77
} finally {
75
78
if ( typeof finalizer === 'function' ) {
You can’t perform that action at this time.
0 commit comments