[Bug] A slash command handler that throws rejects out of the dispatcher and ends the app
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
- In a script register a command:
commandRegistry.register({name: 'boom', description: 'x', handler: async () => { throw new Error('disk full'); }}) - Call
dispatchSlashCommand('/boom', options)with anonCommandCompletethat 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 callcompleteCommand. The existingfinallyonly clears the progress spinner.- Add a test with a throwing command checking that
onCommandCompleteis called and nothing rejects.
Related: PR #2138, #2098 (dispatcher refactors).
I’m working on the focused dispatcher fix for this issue.
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.
I found the existing open PR #2210 covering this fix, so I’m standing down to avoid a duplicate.