Skip to content

Ending input at the yes/no question should count as "no", not crash with exit 13 #22

Backlog

Description

@xgame92

What

Before deploy or update changes anything, it asks a yes/no question on the terminal. If the person presses Ctrl-D (end of input) instead of answering, the question is never answered. Node then exits with code 13 and prints "Warning: Detected unsettled top-level await", instead of the CLI's own exit 7 and "Nothing was created." Scripts and agents rely on the documented exit codes (7 means "No yes: declined ... nothing was created"), and 13 isn't one of them. Treating end of input as "no" gives the documented result.

Where to look

  • packages/cli/src/system.ts, lines 120-128, confirm:
    const rl = createInterface({ input: process.stdin, output: process.stderr });
    try {
    	const answer = await new Promise<string>((resolve) => rl.question(question, resolve));
    When input ends, readline closes the interface and the question callback never runs. Listen for the interface's close event too, and resolve with an empty answer.
  • packages/cli/src/bin.ts, line 5: the CLI runs main with top-level await. That is why an unsettled promise turns into exit 13.
  • packages/cli/src/deploy-track.ts, lines 816-833: what happens with a false answer (a CliError with not-confirmed, exit 7).
  • confirm reads process.stdin directly, which is hard to test. A small helper that takes the input and output streams, used by confirm, can be tested with a PassThrough from node:stream that you end at once. system.ts has no test file yet. Use the style of packages/cli/test/version.test.ts.
  • Leave Ctrl-C as it is. This issue is only about end of input.

Done when

  • With input that ends before any answer, the question resolves to "no". A test with an ended PassThrough shows this, and it hangs or fails without the change (give it a short timeout).
  • Answers y, yes and YES still mean yes, and anything else means no, as /^y(es)?$/i says today. A test covers these.
  • pnpm verify passes.

How to check

pnpm install
pnpm --filter gateweave test
pnpm verify

To see it by hand, after pnpm build: run node packages/cli/dist/bin.js deploy track in a terminal against an empty rehearsal account, and press Ctrl-D at the question. Only do this in a separate, empty Cloudflare account, as CONTRIBUTING.md says. The unit test is enough for the pull request.

The draft pull request #18 changes the same files (main.ts, system.ts). If it merges before you open yours, rebase on main first.

Setup is in CONTRIBUTING.md. Say here if you're taking this, so nobody does it twice, and ask here if you get stuck.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions