summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBo Ørsted Andresen <bo.andresen@zlin.dk>2007-02-28 10:19:20 +0000
committerBo Ørsted Andresen <bo.andresen@zlin.dk>2007-02-28 10:19:20 +0000
commit7b76a36b0ce28b4839fa624e4dad3c4a7e4d1f03 (patch)
tree21267f4691e53c6afd60c21247c10672f4bbc13b
parentf17c0e310014f1c26b11d1896d0aecc3b92fe6d3 (diff)
downloadwgetpaste-7b76a36b0ce28b4839fa624e4dad3c4a7e4d1f03.tar.gz
Add some error handling.
-rwxr-xr-xwgetpaste13
1 files changed, 10 insertions, 3 deletions
diff --git a/wgetpaste b/wgetpaste
index f2976ea..a7e9db3 100755
--- a/wgetpaste
+++ b/wgetpaste
@@ -20,9 +20,7 @@ EOF
}
escape() {
- local text=$*
-
- echo "${text}" | sed -e 's|%|%25|g' -e 's|&|%26|g' -e 's|+|%2b|g' -e 's| |+|g'
+ echo "$*" | sed -e 's|%|%25|g' -e 's|&|%26|g' -e 's|+|%2b|g' -e 's| |+|g'
}
while getopts ":n:l:d:f:h" opt; do
@@ -55,6 +53,12 @@ while getopts ":n:l:d:f:h" opt; do
done
from="${from:-/dev/stdin}"
+
+if [[ ! -r "${from}" ]]; then
+ echo "The input source: \"${from}\" is not readable. Please specify a readable input source with -f. Aborting."
+ exit 1
+fi
+
input="$(escape "$(<${from})")"
nick="${nick:-"$(whoami)"}"
lang="${lang:-"Plain Text"}"
@@ -73,6 +77,9 @@ url=$(wget -O - --timeout=10 --post-data="lang=${lang}&nick=${nick}&desc=${desc}
if [[ "${url}" == "http://rafb.net/p/toofast.html" ]]; then
echo "You must wait at least 10 seconds between each paste! Try again in 10 seconds."
exit 1
+elif [[ -z "${url}" ]]; then
+ echo "Nothing received. Perhaps the connection failed. Please try again later."
+ exit 1
fi
echo "Your paste can be seen here: ${url}"