nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] A null or nameless entry in "providers" crashes startup with a TypeError

Open addyCooks opened this issue 2 weeks ago • 1 comments

Description

Provider entries are not validated when they are loaded. A null entry (or an entry without name) makes config loading throw "Cannot read properties of null (reading 'name')" and the app does not start.

Environment

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

Steps to Reproduce

  1. In an empty folder create agents.config.json:

     {"nanocoder":{"providers":[null,{"models":["m"]}]}}
    
  2. Run getAppConfig() with NANOCODER_CONFIG_DIR set to an empty folder.

Expected Behavior

Each invalid entry is skipped with one clear message, for example providers[0] in <file> is not an object and providers[1] has no "name". The valid entries still load.

Actual Behavior

THROW TypeError: Cannot read properties of null (reading 'name')

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/config/mcp-config-loader.ts:260-275: the code calls providerMap.set(provider.name, provider) for each entry. Filter entries first with a small validator (object, non-empty string name, models is an array if present) and report each rejected entry once. The same validator should be used in loadProjectProviderConfigs (line 281) and loadProviderConfigFromFile (line 329).
  • Add tests for null, a number and an object without name.

addyCooks avatar Nov 16 '26 09:11 addyCooks

I'd like to take this one. Root cause: loadProjectProviderConfigs / the provider loop in source/config/mcp-config-loader.ts reads provider.name without checking the entry is an object, so a null item in providers throws TypeError: Cannot read properties of null (reading 'name') and aborts the whole config load (nameless entries are likewise passed through unvalidated).

Proposal: skip (with a logged warning) any provider entry that is not a non-null object with a string name, so the remaining valid providers still load; add a spec covering [null, valid] and a nameless entry, plus the patch changeset required by AGENTS.md.

Happy to open a PR with that if you're fine with me picking it up.

Disclosure: this comment was drafted with the help of an AI coding assistant (Claude) and reviewed before posting.

pcbeingused33 avatar Nov 17 '26 08:11 pcbeingused33