-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Change DeserializeComponentRef to return error on empty input #8707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
chasm/ref.go
Outdated
| // Provides caller the access to information including ExecutionKey, Archetype, and ShardingKey. | ||
| func DeserializeComponentRef(data []byte) (ComponentRef, error) { | ||
| if len(data) == 0 { | ||
| return ComponentRef{}, serviceerror.NewInternal("empty chasm component ref") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we are using service error, let's switch to InvalidArgument.
| // Provides caller the access to information including ExecutionKey, Archetype, and ShardingKey. | ||
| func DeserializeComponentRef(data []byte) (ComponentRef, error) { | ||
| if len(data) == 0 { | ||
| return ComponentRef{}, errors.New("empty chasm component ref") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Should use InvalidArgument instead of errors.New (Bugbot Rules)
The error returned for empty input uses errors.New instead of serviceerror.NewInvalidArgument. The PR discussion explicitly requested switching to InvalidArgument, and this matches the codebase pattern for invalid input validation as seen in path_encoder.go and visibility.go.
| // Provides caller the access to information including ExecutionKey, Archetype, and ShardingKey. | ||
| func DeserializeComponentRef(data []byte) (ComponentRef, error) { | ||
| if len(data) == 0 { | ||
| return ComponentRef{}, errors.New("empty chasm component ref") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will cause unnecessary retries so I can't approve it.
Currently,
DeserializeComponentRefgiven empty input yields a zero-valueComponentRef. Although this matches the behavior of protoUnmarshal, we don't want to support empty serialized refs. A zero-valueComponentRefcompares less than other values, but it's otherwise mostly invalid (and can't be serialized).Note
Make
DeserializeComponentReferror on empty input and add tests for nil/empty cases.DeserializeComponentRef: Return error on empty input (len(data) == 0); adderrorsimport.TestSerializeDeserializeto assert errors forniland empty byte slices; retain serialization roundtrip checks.Written by Cursor Bugbot for commit f968d82. This will update automatically on new commits. Configure here.