Skip to content
This repository has been archived by the owner on Sep 14, 2019. It is now read-only.

Commit

Permalink
Rearrange validation so that the user only ever sees errors
Browse files Browse the repository at this point in the history
*after* providing input.

In particular if the existing config does not validate then we
should just ensure that the problematic question is displayed
without a confusing error message beforehand; the error should
only appear if the newly entered response doesn't validate.
  • Loading branch information
mutability committed Dec 10, 2014
1 parent 3af0fb5 commit 1cdfe8d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions debian/dump1090-mutability.config
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,32 @@ db_input_verify() {
db_input $PRI $KEY; RESULT=$?
db_go
set -e
ASKED=0
while :
do
db_get $KEY
if $VERIFY $RET; then return 0; fi
if [ $RESULT -ne 0 ]; then
# db_input failed, and the existing value does not validate
if [ $RESULT = 30 ] && [ $PRI != high ]
if [ $RESULT = 30 ] && [ $ASKED = 0 ]
then
# question wasn't displayed, but existing value is invalid
# bump priority and try again
PRI=high
# question was skipped, but existing value is invalid
# bump priority and try again (once)
PRI=high
ASKED=1
else
# give up, use the default value
db_reset $KEY
return 0
fi
else
# db_input was OK, but the value did not verify.
# show an error message
db_input high dump1090-mutability/invalid-$VERIFY || true
fi

# db_input was OK, but the value did not verify.
# display an error and try again.
# try again
set +e
db_input high dump1090-mutability/invalid-$VERIFY
db_fset $KEY seen false
db_input high $KEY; RESULT=$?
db_go
Expand Down

0 comments on commit 1cdfe8d

Please sign in to comment.