Skip to content

Commit afcb914

Browse files
committed
consider backticks when truncating
1 parent 1ecd3fd commit afcb914

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

apps/webapp/app/v3/services/alerts/deliverAlert.server.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ export class DeliverAlertService extends BaseService {
631631
type: "section",
632632
text: {
633633
type: "mrkdwn",
634-
text: `\`\`\`${this.#truncateSlackText(error.stackTrace ?? error.message)}\`\`\``,
634+
text: this.#wrapInCodeBlock(error.stackTrace ?? error.message),
635635
},
636636
},
637637
{
@@ -743,7 +743,7 @@ export class DeliverAlertService extends BaseService {
743743
type: "section",
744744
text: {
745745
type: "mrkdwn",
746-
text: `\`\`\`${this.#truncateSlackText(error.stackTrace ?? error.message)}\`\`\``,
746+
text: this.#wrapInCodeBlock(error.stackTrace ?? error.message),
747747
},
748748
},
749749
{
@@ -843,9 +843,7 @@ export class DeliverAlertService extends BaseService {
843843
type: "section",
844844
text: {
845845
type: "mrkdwn",
846-
text: `\`\`\`${this.#truncateSlackText(
847-
preparedError.stack ?? preparedError.message
848-
)}\`\`\``,
846+
text: this.#wrapInCodeBlock(preparedError.stack ?? preparedError.message),
849847
},
850848
},
851849
{
@@ -1071,9 +1069,20 @@ export class DeliverAlertService extends BaseService {
10711069
};
10721070
}
10731071

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;
10771086
}
10781087

10791088
return text;

0 commit comments

Comments
 (0)