@@ -631,7 +631,7 @@ export class DeliverAlertService extends BaseService {
631
631
type : "section" ,
632
632
text : {
633
633
type : "mrkdwn" ,
634
- text : `\`\`\` ${ this . #truncateSlackText ( error . stackTrace ?? error . message ) } \`\`\`` ,
634
+ text : this . #wrapInCodeBlock ( error . stackTrace ?? error . message ) ,
635
635
} ,
636
636
} ,
637
637
{
@@ -743,7 +743,7 @@ export class DeliverAlertService extends BaseService {
743
743
type : "section" ,
744
744
text : {
745
745
type : "mrkdwn" ,
746
- text : `\`\`\` ${ this . #truncateSlackText ( error . stackTrace ?? error . message ) } \`\`\`` ,
746
+ text : this . #wrapInCodeBlock ( error . stackTrace ?? error . message ) ,
747
747
} ,
748
748
} ,
749
749
{
@@ -843,9 +843,7 @@ export class DeliverAlertService extends BaseService {
843
843
type : "section" ,
844
844
text : {
845
845
type : "mrkdwn" ,
846
- text : `\`\`\`${ this . #truncateSlackText(
847
- preparedError . stack ?? preparedError . message
848
- ) } \`\`\``,
846
+ text : this . #wrapInCodeBlock( preparedError . stack ?? preparedError . message ) ,
849
847
} ,
850
848
} ,
851
849
{
@@ -1071,9 +1069,20 @@ export class DeliverAlertService extends BaseService {
1071
1069
} ;
1072
1070
}
1073
1071
1074
- #truncateSlackText( text : string ) {
1075
- if ( text . length > 3000 ) {
1076
- return text . slice ( 0 , 2900 ) + "\n\ntruncated - check dashboard for complete error message" ;
1072
+ #wrapInCodeBlock( text : string , maxLength = 3000 ) {
1073
+ return `\`\`\`${ this . #truncateSlackText( text , maxLength - 10 ) } \`\`\`` ;
1074
+ }
1075
+
1076
+ #truncateSlackText( text : string , length = 3000 ) {
1077
+ if ( text . length > length ) {
1078
+ logger . debug ( "[DeliverAlert] Truncating slack text" , {
1079
+ length,
1080
+ originalLength : text . length ,
1081
+ } ) ;
1082
+
1083
+ const truncationSuffix = "\n\ntruncated - check dashboard for complete error message" ;
1084
+
1085
+ return text . slice ( 0 , length - truncationSuffix . length ) + truncationSuffix ;
1077
1086
}
1078
1087
1079
1088
return text ;
0 commit comments