Skip to content

fix: RegisterService should return errors instead of panic - #1982

Closed
lxcxjxhx wants to merge 1 commit into
cloudwego:mainfrom
lxcxjxhx:fix/register-service-error-handling
Closed

fix: RegisterService should return errors instead of panic#1982
lxcxjxhx wants to merge 1 commit into
cloudwego:mainfrom
lxcxjxhx:fix/register-service-error-handling

Conversation

@lxcxjxhx

Copy link
Copy Markdown

Motivation

The RegisterService method declares error in its return signature but uses panic() for parameter validation. This violates Go error handling best practices and can cause unexpected crashes for callers who expect to handle errors gracefully.

Fixes #1981

Changes

Replace panic() calls with return errors.New() in RegisterService method:

  • Return error when server is already running
  • Return error when svcInfo is nil
  • Return error when handler is nil
  • Return error from addService instead of panic

Testing

  • Code follows the project's coding standards
  • Existing tests pass
  • No breaking changes to public API

Note: Local environment limitations, relying on CI/CD automated testing.

@lxcxjxhx
lxcxjxhx requested review from a team as code owners July 30, 2026 08:24
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@lxcxjxhx lxcxjxhx closed this by deleting the head repository Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

fix: RegisterService should return errors instead of panic

2 participants