Skip to content

fix: stop waiting for input on interrupt - #8

Merged
tisonkun merged 2 commits into
scopedb:mainfrom
tyranitar-mega:fix-ctrl-c
Sep 11, 2026
Merged

tisonkun merged 2 commits into
scopedb:mainfrom
tyranitar-mega:fix-ctrl-c

Conversation

@tyranitar-mega

Copy link
Copy Markdown
Contributor

Summary

  • Stop waiting for input when a command is interrupted, so Ctrl+C at a prompt such as scope login or scope apikey revoke exits promptly with the interrupted exit code instead of waiting for the line to be submitted.
  • Render interruptions as a bare newline, so the pending prompt line is terminated and no failure is reported that the user already knows about.

Design Notes

os.Stdin reads cannot be interrupted by a signal: the descriptor is not registered with the runtime poller, so SetReadDeadline reports os.ErrNoDeadline and internal/poll retries the read on EINTR. readLine therefore reads in a goroutine and stops waiting once the command context ends.

A prompt read cannot be interrupted by a signal, so Ctrl+C at a prompt waited until the line was submitted. Cancel the read with the command context and render interruptions as a bare newline.
Comment thread cmd/scope/main_test.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe redundant tests?

Comment thread cmd/scope/main.go Outdated
Comment on lines +49 to +55
func renderError(err error) string {
// An interrupted command ends the pending line instead of reporting a failure the user already knows about.
if clierror.ExitCode(err) == clierror.ExitInterrupted {
return "\n"
}
return clierror.Render(err)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.. and then this function can be inlined further.

@tisonkun

Copy link
Copy Markdown
Contributor

I'm patching this PR now.

Signed-off-by: tison <wander4096@gmail.com>
@tisonkun
tisonkun merged commit 6c77276 into scopedb:main Sep 11, 2026
1 check passed
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.

2 participants