[Bug] Provider connection errors do not say which provider or URL failed, or why ("Connection failed: Unable to reach the model server", "Invalid URL", "bad port")
Description
When a provider cannot be reached, the message does not include the provider name, the URL, or the cause. A refused connection and an unknown host print the same text. Bad URLs print a raw one-word error from Node. The error for an HTTP failure from the same parser does include the URL and response body, so the information is available.
Environment
- OS: Windows 11 (10.0.26300)
- Node version: 22.22.3
- Nanocoder version: 1.31.0 (main at 9d88dda7)
- Provider: a provider named "MyProvider" with a broken
baseUrl - Model: m
Steps to Reproduce
Set a provider {"name":"MyProvider","baseUrl":"<URL>","models":["m"]} and run nanocoder --trust-directory run "hi" for each URL below.
Expected Behavior
Something like: Couldn't reach provider "MyProvider" at http://127.0.0.1:59999/v1 (connection refused). Is the server running? Check baseUrl in <config path>. Different causes give different text.
Actual Behavior
http://127.0.0.1:59999/v1 -> Connection failed: Unable to reach the model server
https://no-such-host.invalid/v1 -> Connection failed: Unable to reach the model server (same text)
http://127.0.0.1:9/v1 -> bad port
${MISSING_URL} -> Invalid URL
(empty) -> Invalid URL
localhost:11434/v1 -> unknown scheme
Suggested Fix
source/ai-sdk-client/error-handling/error-parser.ts:203-213: include the provider name, base URL and the error code (ECONNREFUSED,ENOTFOUND) in the connection message, and add a short hint. Compare with the HTTP branch at lines 89-92, which already addsURL:.- Wrap URL-parse errors (the final fallback near the end of the file) the same way, so a missing env var or a missing
http://is explained. - Add tests with a refused port and an unknown host.
Additional Context
- Related: #1136 (error classification by substring).
- [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
Hey @addyCooks, I'd like to work on this issue.
My approach would be to:
- Trace the
parseAPIError()call sites and pass the provider name and base URL as context where available. - Improve connection error handling to distinguish between errors like
ECONNREFUSEDandENOTFOUND, including the provider details and actionable hints. - Handle malformed URLs and missing schemes with clearer error messages instead of raw Node.js errors.
- Add regression tests covering the reported cases while ensuring existing error handling remains unaffected.
let me know if that works.
Hey @Vishesh-Verma-07, as you can see, I've already been assigned to issue #1742 and have submitted PR #1764 addressing it.
Since both PRs cover the same issue, I'd appreciate it if you could close yours to avoid duplicate work and potential conflicts.
Thanks for understanding!
Thanks both for working on this.
To keep things clear: #1742 was assigned to @Srinidhi444 on 14 Oct (they asked to take it on 13 Oct), so #1764 is the PR we'll review for this issue.
@Vishesh-Verma-07, thanks for the effort on #1762. The issue was already assigned when you opened it, and you hadn't commented on it first. Please close #1762 so we don't have two PRs for one issue. Next time, comment on the issue and wait for assignment before opening a PR. There are other unassigned "good first issue" items you're welcome to take; just ask on the issue first.
One person is assigned per issue, so please don't start work on an assigned issue.