Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions chasm/ref.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package chasm

import (
"errors"
"reflect"

"go.temporal.io/api/serviceerror"
Expand Down Expand Up @@ -128,6 +129,9 @@ func (r *ComponentRef) Serialize(
// DeserializeComponentRef deserializes a byte slice into a ComponentRef.
// 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")
Copy link

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.

Fix in Cursor Fix in Web

Copy link
Member

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.

}
var pRef persistencespb.ChasmComponentRef
if err := pRef.Unmarshal(data); err != nil {
return ComponentRef{}, err
Expand Down
5 changes: 5 additions & 0 deletions chasm/ref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ func (s *componentRefSuite) TestShardingKey() {
}

func (s *componentRefSuite) TestSerializeDeserialize() {
_, err := DeserializeComponentRef(nil)
s.Error(err)
_, err = DeserializeComponentRef([]byte{})
s.Error(err)

executionKey := ExecutionKey{
NamespaceID: primitives.NewUUID().String(),
BusinessID: primitives.NewUUID().String(),
Expand Down
Loading