Repository navigation
fix(cli): say what to do when the inference server is unreachable - #3129
dkosowski87 merged 5 commits into
Conversation
With nothing listening on port 9001, `inference infer` printed the raw urllib3 connection error, which never mentions that a server is needed at all. The SDK already separates the cases: HTTPCallErrorError means the server answered, so a 404 for a missing model still reports as before. Only the base HTTPClientError gets the extra text, pointing at `inference server start`, --host, and the hosted API. Fixes roboflow#314
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
|
CLA is signed now, so this is unblocked - checks are green and it is ready whenever someone has a moment. Short recap of what it does: when the inference server is unreachable, the CLI surfaced the raw connection exception, which reads as a bug in the user's own code rather than "nothing is listening on that address". It now says what happened and what to do about it. Test covers the unreachable path. |
dkosowski87
left a comment
There was a problem hiding this comment.
Hey @tsayin4 thanks for taking this, I left a couple of comments.
| # The server answered, so the request or the model is the problem, not reachability. | ||
| typer.echo(f"Command failed. Cause: {error}") | ||
| raise typer.Exit(code=1) | ||
| except HTTPClientError: |
There was a problem hiding this comment.
This is too broad of a catch. If you look at its children, it also covers missing API keys, invalid model IDs, unsupported tasks, and image encoding errors. Would improve this by:
- A dedicated SDK exception that would make that distinction reliable.
- Preserving the original error message, including for connection failures.
- Raise this dedicated exception only the server request
ConnectionError.
| f"Could not reach an inference server at {host}.\n" | ||
| "\n" | ||
| "`inference infer` sends requests to a server; it does not run the model in this\n" | ||
| "process. Start one locally with `inference server start` (needs Docker), or pass\n" |
There was a problem hiding this comment.
| "process. Start one locally with `inference server start` (needs Docker), or pass\n" | |
| "process. Start one locally with `inference server start` (requires Docker or Podman), or pass\n" |
| "`inference infer` sends requests to a server; it does not run the model in this\n" | ||
| "process. Start one locally with `inference server start` (needs Docker), or pass\n" | ||
| "--host to use a server you already have, for example\n" | ||
| "--host https://detect.roboflow.com for the hosted API." |
There was a problem hiding this comment.
| "--host https://detect.roboflow.com for the hosted API." | |
| "--host https://serverless.roboflow.com for Roboflow’s Serverless Cloud API" |
| "\n" | ||
| "`inference infer` sends requests to a server; it does not run the model in this\n" | ||
| "process. Start one locally with `inference server start` (needs Docker), or pass\n" | ||
| "--host to use a server you already have, for example\n" |
There was a problem hiding this comment.
| "--host to use a server you already have, for example\n" | |
| "--host to for an existing server, for example:\n" |
Add HTTPServerConnectionError (subclass of HTTPClientError, so existing callers are unaffected) and raise it from wrap_errors/wrap_errors_async when the request to the server cannot connect. The CLI now catches only that error, keeps the original SDK message, and points to Docker/Podman and the Serverless API. Other client errors (missing API key, invalid model id, encoding) fall through to the generic message. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fixes #314
I hit this myself before I understood what
inference inferactually does. With nothing listening onport 9001 you get a wall of urllib3 output, and nothing in it says that a server is required at all —
which is exactly what the issue describes.
Before:
After:
The SDK already tells the two cases apart, so the change leans on that rather than inspecting the
message:
HTTPCallErrorErrormeans the server answered, so a 404 for a missing model still reportsthe way it always did. Only the base
HTTPClientError, which the SDK raises when the connectionitself fails, gets the extra text.
I mentioned the hosted API as well as
server start, since someone who does not realise a server isinvolved probably also does not know that the hosted one is an option.
container_adapter.pyalready does something similar for the server commands, so this is the sameidea applied to the one path that was missing it.
Tests in
tests/inference_cli/unit_tests/test_main_infer_errors.pycover the unreachable case, aserver that answered (should keep the old message), and a custom
--hostappearing in the output.226 passedintests/inference_cli/unit_tests— the three collection errors there are missingoptional deps (torch and friends) and happen on
maintoo.Happy to adjust the wording if you would rather it were shorter or pointed somewhere else.
Summary by CodeRabbit