Skip to content

Commit 10dd416

Browse files
committed
fix
1 parent b3f0083 commit 10dd416

4 files changed

Lines changed: 32 additions & 8 deletions

File tree

go-sdk/state/keyed/keyed_map_state.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,14 @@ func (s *KeyedMapState[MK, MV]) All() iter.Seq2[MK, MV] {
181181
return
182182
}
183183

184-
k, _ := s.factory.mapKeyCodec.Decode(keyRaw)
185-
v, _ := s.factory.mapValueCodec.Decode(valRaw)
184+
k, err := s.factory.mapKeyCodec.Decode(keyRaw)
185+
if err != nil {
186+
continue // skip entry on decode error to avoid yielding corrupted zero values
187+
}
188+
v, err := s.factory.mapValueCodec.Decode(valRaw)
189+
if err != nil {
190+
continue
191+
}
186192

187193
if !yield(k, v) {
188194
return

go-sdk/state/keyed/keyed_priority_queue_state.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ func (s *KeyedPriorityQueueState[V]) Poll() (V, bool, error) {
145145
return val, found, err
146146
}
147147

148-
userKey, _ := s.factory.valueCodec.Encode(val)
148+
userKey, err := s.factory.valueCodec.Encode(val)
149+
if err != nil {
150+
return val, true, fmt.Errorf("encode pq element for delete failed: %w", err)
151+
}
149152
ck := api.ComplexKey{
150153
KeyGroup: s.factory.groupKey,
151154
Key: s.primaryKey,
@@ -188,7 +191,10 @@ func (s *KeyedPriorityQueueState[V]) All() iter.Seq[V] {
188191
return
189192
}
190193

191-
v, _ := s.factory.valueCodec.Decode(userKey)
194+
v, err := s.factory.valueCodec.Decode(userKey)
195+
if err != nil {
196+
continue // skip entry on decode error to avoid yielding corrupted zero values
197+
}
192198
if !yield(v) {
193199
return
194200
}

go-sdk/state/structures/map.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,14 @@ func (m *MapState[K, V]) All() iter.Seq2[K, V] {
156156
return
157157
}
158158

159-
k, _ := m.keyCodec.Decode(keyRaw)
160-
v, _ := m.valueCodec.Decode(valRaw)
159+
k, err := m.keyCodec.Decode(keyRaw)
160+
if err != nil {
161+
continue // skip entry on decode error to avoid yielding corrupted zero values
162+
}
163+
v, err := m.valueCodec.Decode(valRaw)
164+
if err != nil {
165+
continue
166+
}
161167

162168
if !yield(k, v) {
163169
return

go-sdk/state/structures/priority_queue.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ func (q *PriorityQueueState[T]) Poll() (T, bool, error) {
115115
return val, found, err
116116
}
117117

118-
userKey, _ := q.valueCodec.Encode(val)
118+
userKey, err := q.valueCodec.Encode(val)
119+
if err != nil {
120+
return val, true, fmt.Errorf("encode pq element for delete failed: %w", err)
121+
}
119122
if err = q.store.Delete(q.ck(userKey)); err != nil {
120123
return val, true, err
121124
}
@@ -149,7 +152,10 @@ func (q *PriorityQueueState[T]) All() iter.Seq[T] {
149152
return
150153
}
151154

152-
v, _ := q.valueCodec.Decode(userKey)
155+
v, err := q.valueCodec.Decode(userKey)
156+
if err != nil {
157+
continue // skip entry on decode error to avoid yielding corrupted zero values
158+
}
153159
if !yield(v) {
154160
return
155161
}

0 commit comments

Comments
 (0)