Skip to content

Commit

Permalink
improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
adrelanos committed Oct 26, 2023
1 parent 44b70c6 commit bb1a166
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions usr/libexec/helper-scripts/curl-prgrs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ mkfifo "$tracefile"

curl_pid="$!"

is_number() {
[[ $1 =~ ^-?[0-9]+$ ]]
}

# By default, the operating system will buffer reads from the progress
# FIFO into chunks. However, we want to process the progress updates as
Expand Down Expand Up @@ -321,13 +324,21 @@ unbuffered_sed \
# first response.
if [ "$tag" = "0000: content-length:" ]; then
length="${line[2]}"
if ! is_number "$length" ; then
echo "$0 ERROR: lenght variable is not a number!" >&2
continue
fi
bytes=0

# Otherwise, if the first two words are `<= recv`, extract the number
# of bytes read and increment the bytes-received counter accordingly,
# then invoke `print_progress`.
elif [ "$tag" = "<= recv" ]; then
size="${line[3]}"
if ! is_number "$size" ; then
echo "$0 ERROR: size variable is not a number!" >&2
continue
fi
bytes=$(( $bytes + $size ))

if [ "$CURL_PRGRS_MAX_FILE_SIZE_BYTES" = "" ]; then
Expand Down

0 comments on commit bb1a166

Please sign in to comment.