Skip to content

Commit 3f0d04e

Browse files
authored
Fix handling of streaming update of unexpected type (Azure#52437)
1 parent ad0be8c commit 3f0d04e

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

sdk/ai/Azure.AI.Agents.Persistent/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
### Breaking Changes
1212

1313
### Bugs Fixed
14+
- Fix handling of streaming update of unexpected type [issue](https://github.com/Azure/azure-sdk-for-net/issues/52407).
1415

1516
### Other Changes
1617

sdk/ai/Azure.AI.Agents.Persistent/src/Custom/Streaming/AsyncStreamingUpdateCollection.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,13 @@ async ValueTask<bool> IAsyncEnumerator<StreamingUpdate>.MoveNextAsync()
212212
return false;
213213
}
214214

215-
var updates = StreamingUpdate.FromEvent(_events.Current);
216-
_updates = updates.GetEnumerator();
215+
IEnumerable<StreamingUpdate> updates = StreamingUpdate.FromEvent(_events.Current);
216+
if (updates is null)
217+
{
218+
StreamingUpdateReason updateKind = StreamingUpdateReasonExtensions.FromSseEventLabel(_events.Current.EventType);
219+
throw new InvalidOperationException($"Unknown streaming update reason {updateKind}");
220+
}
221+
_updates = updates.GetEnumerator();
217222

218223
if (_updates.MoveNext())
219224
{

sdk/ai/Azure.AI.Agents.Persistent/src/Custom/Streaming/StreamingUpdateCollection.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,12 @@ public bool MoveNext()
204204
return false;
205205
}
206206

207-
var updates = StreamingUpdate.FromEvent(_events.Current);
207+
IEnumerable<StreamingUpdate> updates = StreamingUpdate.FromEvent(_events.Current);
208+
if (updates is null)
209+
{
210+
StreamingUpdateReason updateKind = StreamingUpdateReasonExtensions.FromSseEventLabel(_events.Current.EventType);
211+
throw new InvalidOperationException($"Unknown streaming update reason {updateKind}");
212+
}
208213
_updates = updates.GetEnumerator();
209214

210215
if (_updates.MoveNext())

0 commit comments

Comments
 (0)