@@ -37,18 +37,12 @@ function errorReply(err: unknown): DiscordEffect {
3737 } ;
3838}
3939
40- /** Sentry events need to say where they came from without the transcript. */
41- function reportException (
42- err : unknown ,
43- context : DiscordContext ,
44- attributes : Record < string , string > ,
45- ) : void {
46- log . exception ( err instanceof Error ? err : new Error ( String ( err ) ) , {
47- guildId : context . guildId ,
48- channel : context . channel . name ,
49- user : context . user . username ,
50- ...attributes ,
51- } ) ;
40+ /**
41+ * Guild/channel/user ride along ambiently (the gateway stamps them, see
42+ * correlation.ts) — only what's local to the failing handler goes here.
43+ */
44+ function reportException ( err : unknown , attributes : Record < string , string > ) : void {
45+ log . exception ( err instanceof Error ? err : new Error ( String ( err ) ) , attributes ) ;
5246}
5347
5448function isAnswered ( effects : DiscordEffect [ ] ) : boolean {
@@ -62,16 +56,11 @@ async function dispatchCommand(
6256 const { command : name , guildId } = context . event ;
6357 const command = findGuildCommand ( registry , guildId , name ) ;
6458 if ( ! command ) {
65- log . warn ( "discord: unknown command" , { guildId , command : name } ) ;
59+ log . warn ( "discord: unknown command" , { command : name } ) ;
6660 return [ { type : "reply" , content : "Unknown command" , ephemeral : true } ] ;
6761 }
6862
69- log . info ( "discord: command" , {
70- guildId,
71- command : name ,
72- channel : context . channel . name ,
73- user : context . user . username ,
74- } ) ;
63+ log . info ( "discord: command" , { command : name } ) ;
7564
7665 try {
7766 const effects = ( await command . handle ( context ) ) ?? [ ] ;
@@ -81,7 +70,7 @@ async function dispatchCommand(
8170 ? effects
8271 : [ ...effects , { type : "reply" , content : "Command completed" , ephemeral : true } ] ;
8372 } catch ( err ) {
84- reportException ( err , context , { command : name } ) ;
73+ reportException ( err , { command : name } ) ;
8574 return [ errorReply ( err ) ] ;
8675 }
8776}
@@ -95,7 +84,7 @@ async function dispatchAutocomplete(
9584 try {
9685 return [ { type : "autocomplete" , choices : await command . autocomplete ( context ) } ] ;
9786 } catch ( err ) {
98- reportException ( err , context , { command : context . event . command } ) ;
87+ reportException ( err , { command : context . event . command } ) ;
9988 // Still answer the interaction — an empty list renders as "no results".
10089 return [ { type : "autocomplete" , choices : [ ] } ] ;
10190 }
@@ -114,7 +103,7 @@ async function dispatchModal(
114103 try {
115104 return ( await command . handleModal ( context ) ) ?? [ ] ;
116105 } catch ( err ) {
117- reportException ( err , context , { customId : context . event . customId } ) ;
106+ reportException ( err , { customId : context . event . customId } ) ;
118107 return [ errorReply ( err ) ] ;
119108 }
120109}
@@ -131,7 +120,7 @@ async function dispatchMessage(
131120 try {
132121 effects . push ( ...( ( await handler ( context ) ) ?? [ ] ) ) ;
133122 } catch ( err ) {
134- reportException ( err , context , { listener : listener . name } ) ;
123+ reportException ( err , { listener : listener . name } ) ;
135124 }
136125 }
137126 return effects ;
0 commit comments