nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] A slash command handler that throws rejects out of the dispatcher and ends the app

Open addyCooks opened this issue 2 weeks ago • 3 comments

Description

dispatchSlashCommand has no catch around the command run. If a command handler throws, the promise rejects, onCommandComplete is never called, and the rejection reaches the process-level unhandledRejection handler, which starts a shutdown with exit code 1.

Environment

  • OS: Windows 11 Home 10.0.26300
  • Node version: v22.22.3
  • Nanocoder version: 1.32.0 (built from main at f92cce9c)
  • Provider: Not provider-specific
  • Model: Not model-specific

Steps to Reproduce

  1. In a script register a command: commandRegistry.register({name: 'boom', description: 'x', handler: async () => { throw new Error('disk full'); }})
  2. Call dispatchSlashCommand('/boom', options) with an onCommandComplete that prints "complete".

Expected Behavior

The error is shown in the chat (for example "/boom failed: disk full"), the turn completes and the app keeps running.

Actual Behavior

The promise rejects and "complete" is never printed. In the app the call is void onSubmit(...) (source/app/components/chat-input.tsx:297) with no catch, and source/utils/shutdown/shutdown-manager.ts:59-75 answers unhandledRejection with gracefulShutdown(1). I reproduced the rejection. I did not run it in a real terminal, so the exit is from reading the code.

Logs/Screenshots

REJECTED: disk full
(onCommandComplete never called)

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently
  • [x] This issue occurs with the latest version of nanocoder (main)

Suggested fix:

  • source/app/utils/command-dispatcher.ts:173-230 (runRegisteredCommand): wrap the load and execute in a catch, add an error message to the chat queue and still call completeCommand. The existing finally only clears the progress spinner.
  • Add a test with a throwing command checking that onCommandComplete is called and nothing rejects.

Related: PR #2138, #2098 (dispatcher refactors).

addyCooks avatar Nov 14 '26 06:11 addyCooks

I’m working on the focused dispatcher fix for this issue.

badrisatyam1-ctrl avatar Nov 14 '26 09:11 badrisatyam1-ctrl

Picking this up. Plan: wrap the command resolution chain in dispatchSlashCommand so a throwing handler queues /<cmd> failed: <message> in the chat and completes the turn after the render delay, instead of rejecting into unhandledRejection. Tests updated for the dispatcher and the spinner path. PR shortly.

chekerh avatar Nov 14 '26 09:11 chekerh

I found the existing open PR #2210 covering this fix, so I’m standing down to avoid a duplicate.

badrisatyam1-ctrl avatar Nov 14 '26 09:11 badrisatyam1-ctrl