From aff9ef3b1866e059945c1dcfa65300357aeadc60 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sat, 15 Mar 2014 14:32:44 -0700 Subject: [PATCH] better error handling --- meow.sh | 21 +++++++++++++-------- run | 5 +++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/meow.sh b/meow.sh index 15f4983..65d8dd2 100644 --- a/meow.sh +++ b/meow.sh @@ -71,14 +71,19 @@ runfilter() { # {action} [database] done < "$mark" now="$(date +%s)" - for regex in "${searchregex[@]}"; do - while IFS=$SEP read -r time tid title; do - [ -n "${already[$tid]}" ] \ - || $action $time $tid "$title" \ - || break - already[$tid]="$now" - done < <(searchfilter "$db" "${regex:1}") - done + while IFS=$SEP read -r time tid title; do + [ -n "${already[$tid]}" ] \ + || $action $time $tid "$title" \ + || { + echo "[meow.sh] failed to run $action" >&2 + echo "[meow.sh] torrent title: $title" >&2 + echo "[meow.sh] torrent id: $tid" >&2 + break + } + already[$tid]="$now" + done < <(for regex in "${searchregex[@]}"; do + searchfilter "$db" "${regex:1}" + done) rm "$mark" for tid in "${!already[@]}"; do diff --git a/run b/run index af4c70e..cd33a90 100755 --- a/run +++ b/run @@ -4,11 +4,12 @@ SRCDIR="$(readlink -f "$(dirname "$0")" )" # TODO: a way to pass opts to transmission-remote declare -a actions -while getopts 'aph' opt; do +while getopts 'ap' opt; do case $opt in a) actions+=(addtorrent);; p) actions+=(prettify);; - ?) echo -E "usage: $0 [-ap]" 1>&2;; + ?) echo -E "usage: $0 [-ap]" >&2 + return 1;; esac done