Skip to content

cliui.Prompt can drop input on validation errors #203

@spikecurtis

Description

@spikecurtis

cliui.Prompt() uses a buffered reader to read until the first newline to capture one "line" of input from terminal user.

However, if the input fails validation, it re-entrantly calls Prompt() to ask the user for more input. If the original buffered reader has read and buffered some input after the newline, this input is lost and inaccessible to the new Prompt() call.

I believe this is the root cause of errors like this in our validation test: https://github.com/coder/coder/actions/runs/11681622439/job/32527173007

This is a legit bug in our product, but it is unlikely to come up in normal human use of the CLI, since the missing input would have to be available immediately after the newline. That's why I've raised this in coder/internal instead of coder/coder. It could still plausibly come up if someone is interacting with our CLI via an expect-style library, but I would hope our flag options generally make that unnecessary.

We should still fix it for the sake of test flakes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions