Skip to content

fix(server): return error instead of panic in RegisterService validation - #2010

Open
AdamMagued wants to merge 1 commit into
cloudwego:mainfrom
AdamMagued:fix-issue-1981-registerservice-errors
Open

AdamMagued wants to merge 1 commit into
cloudwego:mainfrom
AdamMagued:fix-issue-1981-registerservice-errors

Conversation

@AdamMagued

Copy link
Copy Markdown

What type of PR is this?

fix

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level.

(Optional) Translate the PR title into Chinese.

fix(server): RegisterService 参数校验失败时返回错误而非 panic

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:
In server/server.go, RegisterService declares an error return signature but panicked on validation failures (when the server is running, when svcInfo is nil, when handler is nil, or when internal service registration fails).

This change updates RegisterService and generic service registration helpers (genericserver.RegisterService, genericserver.RegisterUnknownServiceOrMethodHandler) to return descriptive errors instead of panicking. It also introduces safe reflection-based nil checking so typed nil interface values and non-pointer handlers are handled without reflection panics. Comprehensive unit test assertions in server/server_test.go and server/genericserver/server_test.go verify all error paths.

(Optional) Which issue(s) this PR fixes:

Fixes #1981

@AdamMagued
AdamMagued requested review from a team as code owners October 11, 2026 00:46
@CLAassistant

CLAassistant commented Oct 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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