Skip to content

Commit d267aa4

Browse files
committed
Truncate pipeline exception message to a sane size
Fixes #20234.
1 parent f0f22db commit d267aa4

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

redis/asyncio/cluster.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,7 @@ async def _execute(
15931593
if isinstance(result, Exception):
15941594
command = " ".join(map(safe_str, cmd.args))
15951595
msg = (
1596-
f"Command # {cmd.position + 1} ({command}) of pipeline "
1596+
f"Command # {cmd.position + 1} ({self._truncate_command(command)}) of pipeline "
15971597
f"caused error: {result.args}"
15981598
)
15991599
result.args = (msg,) + result.args[1:]
@@ -1637,6 +1637,11 @@ def mset_nonatomic(
16371637

16381638
return self
16391639

1640+
def _truncate_command(self, command, max_length=100):
1641+
if len(command) > max_length:
1642+
return command[:max_length] + "..."
1643+
return command
1644+
16401645

16411646
for command in PIPELINE_BLOCKED_COMMANDS:
16421647
command = command.replace(" ", "_").lower()

redis/client.py

100755100644
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1514,11 +1514,16 @@ def raise_first_error(self, commands, response):
15141514
def annotate_exception(self, exception, number, command):
15151515
cmd = " ".join(map(safe_str, command))
15161516
msg = (
1517-
f"Command # {number} ({cmd}) of pipeline "
1517+
f"Command # {number} ({self._truncate_command(cmd)}) of pipeline "
15181518
f"caused error: {exception.args[0]}"
15191519
)
15201520
exception.args = (msg,) + exception.args[1:]
15211521

1522+
def _truncate_command(self, command, max_length=100):
1523+
if len(command) > max_length:
1524+
return command[:max_length] + "..."
1525+
return command
1526+
15221527
def parse_response(self, connection, command_name, **options):
15231528
result = Redis.parse_response(self, connection, command_name, **options)
15241529
if command_name in self.UNWATCH_COMMANDS:

0 commit comments

Comments
 (0)