Skip to content

Commit

Permalink
Merge pull request #328 from asdil12/poo/164153
Browse files Browse the repository at this point in the history
Limit max error length for curl msgs by cutting msg in the middle
  • Loading branch information
mergify[bot] authored Jul 24, 2024
2 parents e92bc3a + 390a770 commit e34f6eb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions _common
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ exp_retry() {
sleep "$wait_sec"
}

# shorten a string in the middle, if it is too large
shorten_string() {
local sstring="$1"
local max_str_len=${max_str_len:-"120"}
local max_str_len_half=$((max_str_len / 2))
if [[ ${#sstring} -gt $max_str_len ]]; then
sstring=${sstring:0:$max_str_len_half}${sstring: -$max_str_len_half}
fi
echo "$sstring"
}

# Wrapper around curl that reports the HTTP status if it is not 200, and the
# calling command and line
# exp_retries: number of total tries - 0/unset for no retries. Sleep before each retry will double.
Expand All @@ -94,6 +105,7 @@ runcurl() {
rc=$?
set -e
if [[ "$rc" != 0 ]]; then
response=$(shorten_string "$response")
warn "curl ($(caller)): Error fetching ($*): $response"
# shellcheck disable=SC2015
exp_retry "$exp_retries" "$retry_exponent" && continue || break
Expand Down

0 comments on commit e34f6eb

Please sign in to comment.