Skip to content

Stop confirmation prompts from looping forever on stdin EOF - #467

Merged
mbrt merged 1 commit into
masterfrom
bug/464
Sep 26, 2026
Merged

mbrt merged 1 commit into
masterfrom
bug/464

Conversation

@mbrt

@mbrt mbrt commented Sep 26, 2026

Copy link
Copy Markdown
Owner

askYN only accepted an answer when ReadString returned no error, and reprompted otherwise. Once stdin reaches EOF (e.g. gmailctl apply </dev/null, a background job or a CI runner), every subsequent read fails immediately with io.EOF, so the loop printed "invalid choice" and reprompted forever instead of exiting.

askOptions, used by gmailctl edit, had the same problem: fmt.Scanln keeps returning io.EOF, which was treated like any other invalid input.

Treat the end of input as the final answer:

  • askYN defaults to "no", the same as an empty line, so apply exits without changing anything. An answer typed without a trailing newline (e.g. printf y | gmailctl apply) is still honored, since that is clearly what the user meant.
  • askOptions returns an error, which edit turns into an abort. This leaves the original config untouched and prints where the edited copy was saved, exactly like choosing "abort". Choosing "no (continue editing)" instead would reopen the editor and hit the same EOF again.

In both cases a newline is printed, so that what follows doesn't end up on the prompt line.

The prompts now take their input and output streams as arguments, so this behavior is covered by unit tests.

Close #464.

askYN only accepted an answer when ReadString returned no error, and
reprompted otherwise. Once stdin reaches EOF (e.g. `gmailctl apply
</dev/null`, a background job or a CI runner), every subsequent read
fails immediately with io.EOF, so the loop printed "invalid choice" and
reprompted forever instead of exiting.

askOptions, used by `gmailctl edit`, had the same problem: fmt.Scanln
keeps returning io.EOF, which was treated like any other invalid input.

Treat the end of input as the final answer:

- askYN defaults to "no", the same as an empty line, so `apply` exits
  without changing anything. An answer typed without a trailing
  newline (e.g. `printf y | gmailctl apply`) is still honored, since
  that is clearly what the user meant.
- askOptions returns an error, which `edit` turns into an abort. This
  leaves the original config untouched and prints where the edited
  copy was saved, exactly like choosing "abort". Choosing "no
  (continue editing)" instead would reopen the editor and hit the same
  EOF again.

In both cases a newline is printed, so that what follows doesn't end up
on the prompt line.

The prompts now take their input and output streams as arguments, so
this behavior is covered by unit tests.

Close #464.
@mbrt mbrt added the kind/bug Something isn't working label Sep 26, 2026
@codecov

codecov Bot commented Sep 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.12500% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.37%. Comparing base (f1f0aef) to head (abc3c43).

Files with missing lines Patch % Lines
cmd/gmailctl/cmd/edit_cmd.go 0.00% 6 Missing ⚠️
cmd/gmailctl/cmd/apply_cmd.go 0.00% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (78.12%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #467      +/-   ##
==========================================
+ Coverage   39.22%   41.37%   +2.14%     
==========================================
  Files          54       54              
  Lines        3681     3693      +12     
==========================================
+ Hits         1444     1528      +84     
+ Misses       2136     2063      -73     
- Partials      101      102       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mbrt
mbrt merged commit f51825d into master Sep 26, 2026
3 of 4 checks passed
@mbrt
mbrt deleted the bug/464 branch September 26, 2026 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

apply's confirmation prompt hangs forever on stdin EOF instead of treating it as N

1 participant