improve error handling
[pdt.git] / pdt.sh
diff --git a/pdt.sh b/pdt.sh
index 66501d168b48f3cc4a30bf5708487d1fb4cb7028..d8fd978f733d4dbd32d73b4c75201fed2a795d75 100644 (file)
--- a/pdt.sh
+++ b/pdt.sh
@@ -80,7 +80,7 @@ tweet() {
         | grep -Fx 'You are not allowed to create a Tweet with duplicate content.' &>/dev/null; then
       # We dont output duplicate error when not in verbose mode, because it is
       # is pretty easy to trigger.
-      if grep -qFx -- "$post_info" ~/pdt/tweets.log; then
+      if [[ -s ~/pdt/tweets.log ]] && grep -qFx -- "$post_info" ~/pdt/tweets.log; then
         if $verbose; then
           echo "pdt: error: post failed. twitter and our log says this tweet is duplicate." >&2
         fi
@@ -105,8 +105,8 @@ tweet() {
     fi
   done
   if [[ $line ]]; then
-    if grep -qFx -- "$post_info" ~/pdt/tweets.log; then
-      echo "pdt: this tweet was a duplicate according to our log but unexpected was allowed."
+    if [[ -s ~/pdt/tweets.log ]] && grep -qFx -- "$post_info" ~/pdt/tweets.log; then
+      echo "pdt: this tweet was a duplicate according to our log but unexpectedly was allowed."
     else
       printf "%s\n" "$post_info" >> ~/pdt/tweets.log
     fi
@@ -223,8 +223,11 @@ toot() {
 #   splitting it in 2 for twitter, you could put the least important
 #   hash tag and the end and omit it on twitter.
 #
-# Twitter considers all urls to be 23 characters. To measure the length
-# of arguments in a file, run this (replace FILE).
+# Twitter considers all urls to be 23 characters.
+#
+# To search a file of posts for any posts with longer than 280
+# characters which haven't been split with /tnt/, run the following
+# (replacing FILE with a path like /home/common/campaigns/pdt/pdt.txt).
 #
 # sed -r 's,/teof/.*,,;s/ *-(m|a|-dbd) [^ ]*//;s,https?://[^ ]*,https://xxxxxxxxxxxxxxx,g' FILE | awk '$0 !~ /\/tnt\// && length > 280 {print length, $0}'
 #
@@ -367,7 +370,7 @@ pdt() {
   fi
   if (( ${#fails[@]} )); then
     printf "%s\n" "$(tput setaf 5 2>/dev/null ||:)${_pdtsh_blocks:0:${COLUMNS:-60}}$(tput sgr0 2>/dev/null||:)"
-    echo "FSF ERROR: ${fails[*]} might not have posted" >&2
+    echo "FSF ERROR: ${fails[*]} might not have posted. post text: $text" >&2
   fi
 }