fix(jsonrpc): prevent nil pointer panic on unregistered service path#3314
fix(jsonrpc): prevent nil pointer panic on unregistered service path#3314cvictory wants to merge 1 commit into
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3314 +/- ##
==========================================
+ Coverage 50.79% 51.22% +0.43%
==========================================
Files 488 488
Lines 44203 36566 -7637
==========================================
- Hits 22451 18730 -3721
+ Misses 20242 16322 -3920
- Partials 1510 1514 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Fixes a JSON-RPC server panic when requests target an unregistered service path by validating exporter lookup results and returning a clear error instead of type-asserting a nil value.
Changes:
- Add
okcheck aroundExporterMap().Load(path)inserveRequest()and returnservice not foundwhen missing. - Add a regression test to ensure unregistered paths return HTTP 500 with an explanatory error (and do not panic).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
protocol/jsonrpc/server.go |
Prevents nil pointer panic by handling missing exporter lookups with a returned error. |
protocol/jsonrpc/server_test.go |
Adds coverage for unregistered-path requests to verify error response and no panic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@cvictory 展图,todo: |
|
this issue have been solved in #3312 is this pr still needed? |



Bug
ExporterMap().Load(path)inserveRequest()discards theokreturn value. When path is not registered,exporteris nil, and the type assertionexporter.(*JsonrpcExporter)panics.Fix
okreturn value fromExporterMap().Load(path)!ok, returnperrors.Errorf("service not found: %s", path)instead of proceeding to type-assert a nil valueVerification
TestHandlePkg_UnregisteredPath— sends valid JSON-RPC request to unregistered path, asserts HTTP 500 with "service not found" (no panic)TestHandlePkg_ContentTypesub-tests passprotocol/jsonrpcpassgo vet ./protocol/jsonrpc/passesCloses #3310