[Bug] nanocoder run hides config, hook, formatter and plugin errors, and reports invalid JSON as "No providers configured"
Description
In run / --plain mode, config problems are only written to the log file, so the user sees nothing. logError and logWarning in source/utils/message-queue.tsx fall back to the file logger when no Ink queue is registered, and the plain shell never registers one. On top of that, source/plain/initialize.ts rewrites every config error into "No providers configured", so a broken agents.config.json hides its real cause. nanocoder config list on the same file does report the real error.
Environment
- OS: Windows 11 (10.0.26300)
- Node version: 22.22.3
- Nanocoder version: 1.31.0 (main at 5c2e693)
- Provider: Ollama
- Model: qwen2.5:1.5b
Steps to Reproduce
- Put invalid JSON in the global
agents.config.json:{"nanocoder":{"providers":[{"name":"Ollama",}]}}(trailing comma). - Run
nanocoder --trust-directory run "say hi". - Run
nanocoder config listagainst the same file. - Fix the provider. Then add these mistakes to a project
agents.config.json:"autoCommit": "yes", a hook namedpost-tool-uze, and a formatter with nocommand. Also add.nanocoder/plugins/bad.mjscontainingthrow new Error("boom"). - Run
nanocoder --trust-directory run "Reply with OK". - Run step 5 again with
NANOCODER_LOG_LEVEL=warn.
Expected Behavior
Each problem is printed on stderr, and included in the --json output. For invalid JSON, the error names the problem, like config list does.
Actual Behavior
Step 2 prints only this and exits 1 (the --json output says the same):
No providers configured. Run nanocoder interactively to set them up.
Step 3 shows the real cause:
unreadable: Expected double-quoted property name in JSON at position 44 (line 1 column 45)
Step 5 exits 0 and prints only the banner and [plain] done. None of the four mistakes is shown.
Step 6 prints them, so they are only being swallowed:
Invalid hooks config: unknown lifecycle event 'post-tool-uze'.
Invalid formatters config: entries need a 'command' string and a non-empty 'match' glob list.
nanocoder.autoCommit must be true or false (got "yes"); treating as off
Plugin bad.mjs failed to load: boom from plugin
Suggested Fix
- In
runPlainShell(source/plain/shell.ts), register a message-queue sink that writes errors and warnings to stderr, and adds them to the--jsonreport aswarnings[]. - In
source/plain/initialize.ts(thecatcharoundcreateLLMClient, about lines 84-92), only use "No providers configured" when the config really is empty. Otherwise pass the real error through. - Add a test that runs the CLI with a broken config and checks stderr.
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
Taking this issue will propose my plan after dignosing the issue properly :)
Here is my approach as promised let me know what you think about this
Implementation Approach
-
Pluggable Message Sink (
source/utils/message-queue.tsx):- Add
setMessageQueueSink(sink: MessageQueueSink | null)allowing non-Ink/headless runners to intercept typed log messages (error,warning,info). - In
addTypedMessage, route messages to the registered sink whenglobalAddToChatQueueis not active.
- Add
-
Plain Shell Warning Collection & Stderr Forwarding (
source/plain/shell.ts):- Register a sink at startup in
runPlainShellthat prints errors and warnings directly toprocess.stderr(leavingstdoutclean for conversation output and JSON). - Buffer warnings in memory and include
warnings: string[]in the--jsonoutput payload for both success and error exits. - Clean up the sink upon exit / shutdown.
- Register a sink at startup in
-
Preserve Accurate Config Errors (
source/plain/initialize.ts):- Differentiate truly empty configs from JSON syntax errors or file read errors so exact parse diagnostics are passed through to
stderr(matchingnanocoder config list).
- Differentiate truly empty configs from JSON syntax errors or file read errors so exact parse diagnostics are passed through to
-
Testing & Verification:
- Add integration tests asserting
stderrand--jsonwarnings[]output for:- Malformed JSON in
agents.config.json - Unknown hook lifecycle events
- Formatters with missing
command - Type mismatches in config (e.g.,
autoCommit: "yes") - Failing plugins (
bad.mjs)
- Malformed JSON in
- Run full verification suite (
test:ava,test:types,test:format,test:knip,test:security).
- Add integration tests asserting