proxy: fix panic on invalid protocol enum#498
Open
fakhriaunur wants to merge 1 commit into
Open
Conversation
4b9c11b to
ce5bb81
Compare
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.
Summary
Fix panic on invalid protocol enum in
Addrs()andAddr()methods by returning an error instead.When an invalid protocol enum is passed to
Addrs()orAddr(), the methods currently panic with a string message. This change replaces the panic with a proper error return usingerrors.ErrBadEnumValue, following the existing error handling pattern in the codebase.Changes
Addrs()method signature to return(addrs []net.Addr, err error)Addr()method signature to return(addr net.Addr, err error)panic()in default case withreturn nil, fmt.Errorf("proto: %w: %q", errors.ErrBadEnumValue, proto)TestProxy_Addr_InvalidProtoTestProxy_Addrs_InvalidProtoRoot Cause
The TODO comment in
proxy/proxy.go:506explicitly suggests usingErrBadEnumValue:Testing
Code Change Statistics
Technical Details
The fix follows the established error handling pattern in
golibs/errors:This pattern is already used in
proxy/config.go:304for upstream mode validation.Issues
Related to H2 in contrib-cat.md
Checklist
go test ./proxy/)go test -race ./proxy/)go vet ./proxy/)Note: This is a minimal fix that replaces panic with proper error handling. The method signatures have been updated to return errors, and all existing call sites have been updated to handle the new return values.