Skip to content

fix(enter): re-prompt instead of aborting on invalid input#16

Open
CheapFuck wants to merge 1 commit into
codam-coding-college:mainfrom
CheapFuck:fix/enter-invalid-input-reprompt
Open

fix(enter): re-prompt instead of aborting on invalid input#16
CheapFuck wants to merge 1 commit into
codam-coding-college:mainfrom
CheapFuck:fix/enter-invalid-input-reprompt

Conversation

@CheapFuck

Copy link
Copy Markdown

Summary

When towel enter finds no towel container, it asks whether to create one. Answering with anything other than yes/no (a typo) aborts the command instead of asking again.

Root cause

The prompt is a while builtin read loop, but an unconditional exit 1 sits after the case, inside the loop body:

while builtin read -rp "Create it now? yes|No:"; do
    case "$REPLY" in
    y | yes | Y | Yes | YES) towel create; break ;;
    n | no | N | No | NO)    exit ;;
    *)                       echo "Invalid input." 1>&2 ;;
    esac
    exit 1   # <- always runs for the '*' branch
done

The yes branch breaks and the no branch exits, so the only path that reaches exit 1 is the * (invalid) branch. The loop can therefore never iterate — a single invalid answer prints Invalid input. and exits with status 1.

Fix

Remove the stray exit 1. Invalid input now falls through and the loop re-prompts as intended; yes/no behaviour is unchanged.

Testing

  • shellcheck -x across all scripts: pass
  • shfmt -d across all scripts: pass

Related to #13 (the container-existence check it asks for is already in place; this fixes the remaining re-prompt bug in that flow). Happy to adjust the linkage if you'd prefer.

When 'towel enter' finds no container, it asks whether to create one in a
while-read loop. An unconditional 'exit 1' sat after the case statement,
inside the loop body, so any answer that fell through to the '*' (invalid)
branch printed "Invalid input." and then immediately exited with status 1.
The loop could therefore never iterate, defeating the purpose of prompting:
a single typo aborted the command instead of asking again.

Remove the stray 'exit 1'. The yes branch already breaks (then enters the
container) and the no branch exits, so invalid input now falls through and
the loop re-prompts as intended.

Related to codam-coding-college#13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant