Rearrange validation so that the user only ever sees errors

*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.
This commit is contained in:
Oliver Jowett 2014-12-10 21:20:31 +00:00
parent 3af0fb51b5
commit 1cdfe8db27

View file

@ -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