Repository navigation
fix: replace panic with proper error handling in RPC client and lookup service - #1403
Merged
Merged
Conversation
RobertIndie
force-pushed
the
fix-rpc-client-panic
branch
from
July 30, 2025 10:26
012a048 to
a5dd90f
Compare
RobertIndie
marked this pull request as ready for review
July 30, 2025 10:48
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request replaces panic-based error handling with proper error returns in the RPC client and lookup service components to improve application stability and graceful error handling.
- Modified RPC client interface to return errors instead of panicking on invalid URLs or configuration issues
- Updated all callers to handle the new error returns from LookupService() and NewRPCClient()
- Added comprehensive test coverage for error scenarios that previously caused panics
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pulsar/internal/rpc_client.go | Modified LookupService() and NewRPCClient() to return errors instead of panicking |
| pulsar/internal/rpc_client_test.go | Added tests to verify error handling for invalid URLs and schemes |
| pulsar/client_impl.go | Updated client initialization to handle RPC client creation errors |
| pulsar/producer_partition.go | Modified lookupTopic() to handle LookupService() error returns |
| pulsar/consumer_partition.go | Updated lookupTopic() to handle LookupService() error returns |
| pulsar/internal/lookup_service_test.go | Updated mock implementations to match new interface signature |
Comments suppressed due to low confidence (2)
pulsar/consumer_partition.go:1941
- The error handling path for LookupService() in consumer partition's lookupTopic() method lacks test coverage. Consider adding tests to verify this error scenario is handled properly.
lr, err := lookupService.Lookup(pc.topic)
pulsar/producer_partition.go:251
- The error handling path for LookupService() in producer partition's lookupTopic() method lacks test coverage. Consider adding tests to verify this error scenario is handled properly.
lr, err := lookupService.Lookup(p.topic)
crossoverJie
approved these changes
Jul 31, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Fixes #1402
The current implementation uses
panic()calls in several critical code paths within the RPC client and lookup service, which can cause the entire application to crash when encountering invalid URLs or configuration errors. This is not a good practice for a client library as it makes the application unstable and difficult to handle gracefully.The main issues addressed:
NewRPCClient()panics when creating lookup service failsLookupService()panics when parsing invalid URLs or creating lookup servicesNewLookupService()panics for invalid URL schemesModifications
LookupService()method signature to return(LookupService, error)instead of justLookupService(RPCClient, error)and handle lookup service creation errors properlypanic()calls with proper error returns and descriptive error messagesVerifying this change
(Please pick either of the following options)
This change is a trivial rework / code cleanup without any test coverage.
(or)
This change is already covered by existing tests, such as (please describe tests).
(or)
This change added tests and can be verified as follows:
(example:)
Does this pull request potentially affect one of the following parts:
If
yeswas chosen, please highlight the changesDocumentation