Skip to content

Commit e34f6eb

Browse files
authored
Merge pull request #328 from asdil12/poo/164153
Limit max error length for curl msgs by cutting msg in the middle
2 parents e92bc3a + 390a770 commit e34f6eb

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

_common

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ exp_retry() {
8080
sleep "$wait_sec"
8181
}
8282

83+
# shorten a string in the middle, if it is too large
84+
shorten_string() {
85+
local sstring="$1"
86+
local max_str_len=${max_str_len:-"120"}
87+
local max_str_len_half=$((max_str_len / 2))
88+
if [[ ${#sstring} -gt $max_str_len ]]; then
89+
sstring=${sstring:0:$max_str_len_half}${sstring: -$max_str_len_half}
90+
fi
91+
echo "$sstring"
92+
}
93+
8394
# Wrapper around curl that reports the HTTP status if it is not 200, and the
8495
# calling command and line
8596
# exp_retries: number of total tries - 0/unset for no retries. Sleep before each retry will double.
@@ -94,6 +105,7 @@ runcurl() {
94105
rc=$?
95106
set -e
96107
if [[ "$rc" != 0 ]]; then
108+
response=$(shorten_string "$response")
97109
warn "curl ($(caller)): Error fetching ($*): $response"
98110
# shellcheck disable=SC2015
99111
exp_retry "$exp_retries" "$retry_exponent" && continue || break

0 commit comments

Comments
 (0)