Skip to content

fix(cli): surface menu errors instead of swallowing them into an infinite loop - #524

Merged
blafourcade merged 1 commit into
nextfrom
fix/e5-02-menu-error-routing
Jul 27, 2026
Merged

blafourcade merged 1 commit into
nextfrom
fix/e5-02-menu-error-routing

Conversation

@blafourcade

Copy link
Copy Markdown
Contributor

🎯 What & why

menu.ts caught every error inside for (;;) and discarded anything that wasn't an ExitPromptError:

} catch (error) {
  if (error instanceof Error && error.name === "ExitPromptError") process.exit(0);
}

No else branch. A deterministic failure — corrupt manifest, unreadable project root, spawn failure — was swallowed, and the loop immediately retried it. The result was an infinite silent spin: the user saw a hung terminal, never an error.

The ticket described this as "menu.ts never calls ErrorHandler.handle", which understated it. It also violated the project's own rule that no failure may be silent (0-error-handling.md); every other command routes through errorHandler.handle — ai.ts alone does so 7 times.

🛠️ How it works

Non-abort errors now go through ErrorHandler: message to stderr, exit 1. Ctrl-C at a prompt still exits 0 silently, unchanged.

Continuing the loop was considered and rejected. All three throw sources here (InteractiveMenuUseCase.execute(), spawnCliCommand, waitForEnter) are menu infrastructure — retrying only reproduces the same failure. Sub-command failures never reach this catch, because spawnCliCommand runs them as subprocesses and returns an exit code rather than throwing.

The decision is extracted as an exported routeMenuError(error, errorHandler). runMenuLoop builds its own deps (createMenuDeps(resolveProjectRoot())) and calls process.exit, so it has no unit coverage today and can't get one without being made injectable — out of scope here. The seam lets the actual fixed behavior be asserted directly, honoring the backlog's rule that every bug fix lands with regression coverage.

🧪 How to verify

pnpm --filter cli test — 2092/2092 (2088 + 4 new), tsc clean.

The 4 new tests were verified to fail (3 of 4) when the silent-swallow is reintroduced, so they genuinely guard the regression rather than just passing.

⚠️ Heads-up

runMenuLoop itself remains untested for the same reason it was untestable before — it isn't dependency-injected. Making it so is a separate concern, not folded in here.

Cartography item A9; planned in the (now-archived) standalone aidd-cli repo before the framework migration (#462).

…nite loop

menu.ts caught every error inside `for (;;)` and discarded anything that was
not an ExitPromptError:

    } catch (error) {
      if (error instanceof Error && error.name === "ExitPromptError") process.exit(0);
    }

With no else branch, a deterministic failure — corrupt manifest, unreadable
project root, spawn failure — was swallowed and the loop immediately retried
it, spinning forever with zero output. The user saw a hung terminal, not an
error. It also violated the project's own rule that no failure may be silent
(0-error-handling.md); every other command routes through
errorHandler.handle (ai.ts alone does so 7 times).

Non-abort errors now go through ErrorHandler: message to stderr, exit 1.
Ctrl-C at a prompt still exits 0 silently, unchanged. Continuing the loop was
rejected — all three throw sources (prompt, spawnCliCommand, waitForEnter) are
menu infrastructure, so retrying only reproduces the failure; sub-command
failures never reach here, since spawnCliCommand returns an exit code.

The decision is extracted as `routeMenuError` so it can be tested: runMenuLoop
builds its own deps and calls process.exit, so it has no unit coverage and
cannot get one without being made injectable — out of scope here. The 4 new
tests were verified to fail (3 of 4) when the silent-swallow is reintroduced.

2092/2092 pass, tsc clean.
@blafourcade
blafourcade force-pushed the fix/e5-02-menu-error-routing branch from b418265 to 7f36185 Compare July 27, 2026 04:32
@blafourcade
blafourcade enabled auto-merge (squash) July 27, 2026 04:33
@blafourcade
blafourcade disabled auto-merge July 27, 2026 04:36
@blafourcade
blafourcade merged commit f1ece43 into next Jul 27, 2026
14 checks passed
blafourcade added a commit that referenced this pull request Jul 31, 2026
…nite loop (#524)

menu.ts caught every error inside `for (;;)` and discarded anything that was
not an ExitPromptError:

    } catch (error) {
      if (error instanceof Error && error.name === "ExitPromptError") process.exit(0);
    }

With no else branch, a deterministic failure — corrupt manifest, unreadable
project root, spawn failure — was swallowed and the loop immediately retried
it, spinning forever with zero output. The user saw a hung terminal, not an
error. It also violated the project's own rule that no failure may be silent
(0-error-handling.md); every other command routes through
errorHandler.handle (ai.ts alone does so 7 times).

Non-abort errors now go through ErrorHandler: message to stderr, exit 1.
Ctrl-C at a prompt still exits 0 silently, unchanged. Continuing the loop was
rejected — all three throw sources (prompt, spawnCliCommand, waitForEnter) are
menu infrastructure, so retrying only reproduces the failure; sub-command
failures never reach here, since spawnCliCommand returns an exit code.

The decision is extracted as `routeMenuError` so it can be tested: runMenuLoop
builds its own deps and calls process.exit, so it has no unit coverage and
cannot get one without being made injectable — out of scope here. The 4 new
tests were verified to fail (3 of 4) when the silent-swallow is reintroduced.

2092/2092 pass, tsc clean.
blafourcade added a commit that referenced this pull request Jul 31, 2026
…nite loop (#524)

menu.ts caught every error inside `for (;;)` and discarded anything that was
not an ExitPromptError:

    } catch (error) {
      if (error instanceof Error && error.name === "ExitPromptError") process.exit(0);
    }

With no else branch, a deterministic failure — corrupt manifest, unreadable
project root, spawn failure — was swallowed and the loop immediately retried
it, spinning forever with zero output. The user saw a hung terminal, not an
error. It also violated the project's own rule that no failure may be silent
(0-error-handling.md); every other command routes through
errorHandler.handle (ai.ts alone does so 7 times).

Non-abort errors now go through ErrorHandler: message to stderr, exit 1.
Ctrl-C at a prompt still exits 0 silently, unchanged. Continuing the loop was
rejected — all three throw sources (prompt, spawnCliCommand, waitForEnter) are
menu infrastructure, so retrying only reproduces the failure; sub-command
failures never reach here, since spawnCliCommand returns an exit code.

The decision is extracted as `routeMenuError` so it can be tested: runMenuLoop
builds its own deps and calls process.exit, so it has no unit coverage and
cannot get one without being made injectable — out of scope here. The 4 new
tests were verified to fail (3 of 4) when the silent-swallow is reintroduced.

2092/2092 pass, tsc clean.
@aidd-bot aidd-bot Bot mentioned this pull request Jul 31, 2026
blafourcade added a commit that referenced this pull request Jul 31, 2026