From: Ian Kelling Date: Tue, 5 Mar 2024 09:59:41 +0000 (-0500) Subject: improve error handling X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=1bed5f3e8e2d50b96cb44ea8f9241c1cb8717623;p=pdt.git improve error handling --- diff --git a/pdt.sh b/pdt.sh index 66501d1..d8fd978 100644 --- 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 }