From ea19e4adc9a6b304347cbcaa4f0913359d95e651 Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Mon, 24 Jul 2023 08:50:08 +0800 Subject: [PATCH] feat: add maximum string length to stacktraces --- src/StackTracePlus.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/StackTracePlus.lua b/src/StackTracePlus.lua index f7fa3e2..c636cef 100644 --- a/src/StackTracePlus.lua +++ b/src/StackTracePlus.lua @@ -240,7 +240,13 @@ function Dumper:DumpLocals (level) elseif type(value) == "boolean" then self:add_f("%s%s = boolean: %s\r\n", prefix, name, tostring(value)) elseif type(value) == "string" then - self:add_f("%s%s = string: %q\r\n", prefix, name, value) + local v = value + if #value > _M.max_str_output_len then + v = string.format("%q ... (truncated, %d bytes)", v:sub(1, _M.max_str_output_len), #v) + else + v = string.format("%q", v) + end + self:add_f("%s%s = string: %s\r\n", prefix, name, v) elseif type(value) == "userdata" then self:add_f("%s%s = %s\r\n", prefix, name, safe_tostring(value)) elseif type(value) == "nil" then