Skip to content

Commit 93715a5

Browse files
committed
Handle failures more gracefully
1 parent ddde2c7 commit 93715a5

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

tokenize

+12-4
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,25 @@ function main() {
6565
# Look first for the m100-tokenize binary in same dir as this script.
6666
PATH=$(dirname "$0"):"$PATH"
6767

68+
local fail=0
6869
if [[ "$dflag" ]]; then
6970
echo "Decommenting and tokenizing '$f' into '$g'"
7071
jumps=$(m100-sanity "$f" | m100-jumps )
71-
m100-sanity "$f" | m100-decomment - "$g" ${jumps}
72+
m100-sanity "$f" | m100-decomment - "$g" ${jumps} || fail=1
7273
elif [[ "$cflag" ]]; then
7374
echo "Decommenting, crunching, and tokenizing '$f' into '$g'"
7475
jumps=$(m100-sanity "$f" | m100-jumps )
75-
m100-sanity "$f" | m100-decomment - - ${jumps} | m100-crunch | m100-tokenize > $g
76+
m100-sanity "$f" | m100-decomment - - ${jumps} | m100-crunch | m100-tokenize > $g || fail=1
7677
else
7778
echo "Tokenizing '$f' into '$g'"
78-
m100-sanity "$f" | m100-tokenize > "$g"
79+
m100-sanity "$f" | m100-tokenize > "$g" || fail=1
80+
fi
81+
82+
echo fail is $fail
83+
if [[ $fail -gt 0 ]]; then
84+
echo "Error detected, removing '$g'" >&2
85+
rm "$g"
86+
exit 1
7987
fi
8088
}
8189

@@ -102,7 +110,7 @@ function output_name() {
102110
fi
103111

104112
# Don't overwrite existing files by default
105-
if [[ -e "$g" && "$g" -nt "$f" ]]; then
113+
if [[ -s "$g" && "$g" -nt "$f" ]]; then
106114
if ! tty -s; then
107115
mv "$g" "$g~" || return -1
108116
else

0 commit comments

Comments
 (0)