Skip to content

Commit 61bb26d

Browse files
committed
Truncate the task output in get_slack_payload to block message limit
Signed-off-by: tdruez <tdruez@nexb.com>
1 parent 97c8052 commit 61bb26d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

scanpipe/models.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4203,11 +4203,19 @@ def get_slack_payload(pipeline_run):
42034203

42044204
# Adds the task output in case of run failure
42054205
if pipeline_run.status == Run.Status.FAILURE and pipeline_run.task_output:
4206+
slack_text_max_length = 3000 # Slack's block message limit
4207+
output_text = pipeline_run.task_output
4208+
# Truncate the task output and add an indicator if it was cut off
4209+
if len(output_text) > slack_text_max_length:
4210+
output_text = (
4211+
output_text[: slack_text_max_length - 30] + "\n... (truncated)"
4212+
)
4213+
42064214
task_output_block = {
42074215
"type": "section",
42084216
"text": {
42094217
"type": "mrkdwn",
4210-
"text": f"```{pipeline_run.task_output}```",
4218+
"text": f"```{output_text}```",
42114219
},
42124220
}
42134221
blocks.append(task_output_block)

0 commit comments

Comments
 (0)