@@ -248,8 +248,10 @@ public async Task<bool> ChatAsync(string input, IShell shell)
248
248
249
249
if ( _copilotResponse . IsError )
250
250
{
251
+ string errorMessage = _copilotResponse . Text ;
252
+ Telemetry . Trace ( AzTrace . Exception ( errorMessage ) ) ;
251
253
host . WriteErrorLine ( )
252
- . WriteErrorLine ( _copilotResponse . Text )
254
+ . WriteErrorLine ( errorMessage )
253
255
. WriteErrorLine ( ) ;
254
256
}
255
257
else
@@ -300,21 +302,25 @@ public async Task<bool> ChatAsync(string input, IShell shell)
300
302
}
301
303
}
302
304
305
+ // The 'ConversationState' could be null when Azure Copilot returns an error response.
303
306
var conversationState = _copilotResponse . ConversationState ;
304
- _turnsLeft = conversationState . TurnLimit - conversationState . TurnNumber ;
305
- if ( _turnsLeft <= 5 )
307
+ if ( conversationState is not null )
306
308
{
307
- string message = _turnsLeft switch
309
+ _turnsLeft = conversationState . TurnLimit - conversationState . TurnNumber ;
310
+ if ( _turnsLeft <= 5 )
308
311
{
309
- 1 => $ "[yellow]{ _turnsLeft } request left[/]",
310
- 0 => $ "[red]{ _turnsLeft } request left[/]",
311
- _ => $ "[yellow]{ _turnsLeft } requests left[/]",
312
- } ;
312
+ string message = _turnsLeft switch
313
+ {
314
+ 1 => $ "[yellow]{ _turnsLeft } request left[/]",
315
+ 0 => $ "[red]{ _turnsLeft } request left[/]",
316
+ _ => $ "[yellow]{ _turnsLeft } requests left[/]",
317
+ } ;
313
318
314
- host . RenderDivider ( message , DividerAlignment . Right ) ;
315
- if ( _turnsLeft is 0 )
316
- {
317
- host . WriteLine ( "\n You've reached the maximum length of a conversation. To continue, please run '/refresh' to start a new conversation.\n " ) ;
319
+ host . RenderDivider ( message , DividerAlignment . Right ) ;
320
+ if ( _turnsLeft is 0 )
321
+ {
322
+ host . WriteLine ( "\n You've reached the maximum length of a conversation. To continue, please run '/refresh' to start a new conversation.\n " ) ;
323
+ }
318
324
}
319
325
}
320
326
0 commit comments