Skip to content

Commit 119e6a8

Browse files
authored
Log the response text if exception is thrown while processing a user query (#338)
The response text is logged to the local log file, not sent to the telemetry, so there is no privacy issue.
1 parent 625d2e0 commit 119e6a8

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

shell/agents/Microsoft.Azure.Agent/AzureAgent.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ public async Task RefreshChatAsync(IShell shell, bool force)
161161
{
162162
IHost host = shell.Host;
163163
CancellationToken cancellationToken = shell.CancellationToken;
164+
165+
_copilotResponse = null;
164166
ResetArgumentPlaceholder();
165167

166168
try
@@ -214,6 +216,9 @@ public async Task<bool> ChatAsync(string input, IShell shell)
214216
IHost host = shell.Host;
215217
CancellationToken token = shell.CancellationToken;
216218

219+
_copilotResponse = null;
220+
ResetArgumentPlaceholder();
221+
217222
if (_turnsLeft is 0)
218223
{
219224
host.WriteLine("\nSorry, you've reached the maximum length of a conversation. Please run '/refresh' to start a new conversation.\n");
@@ -243,8 +248,6 @@ public async Task<bool> ChatAsync(string input, IShell shell)
243248

244249
if (_copilotResponse.ChunkReader is null)
245250
{
246-
ResetArgumentPlaceholder();
247-
248251
if (_copilotResponse.IsError)
249252
{
250253
string errorMessage = _copilotResponse.Text;
@@ -325,11 +328,22 @@ public async Task<bool> ChatAsync(string input, IShell shell)
325328

326329
Telemetry.Trace(AzTrace.Chat(_copilotResponse));
327330
}
328-
catch (Exception ex) when (ex is TokenRequestException or ConnectionDroppedException)
331+
catch (Exception ex)
329332
{
330-
host.WriteErrorLine(ex.Message);
331-
host.WriteErrorLine("Please run '/refresh' to start a new chat session and try again.");
332-
return false;
333+
if (ex is TokenRequestException or ConnectionDroppedException)
334+
{
335+
host.WriteErrorLine(ex.Message);
336+
host.WriteErrorLine("Please run '/refresh' to start a new chat session and try again.");
337+
return false;
338+
}
339+
340+
Log.Error(ex, "Exception thrown when processing the query '{0}'", input);
341+
if (_copilotResponse?.Text is not null)
342+
{
343+
Log.Error("Response text:\n{0}", _copilotResponse.Text);
344+
}
345+
346+
throw;
333347
}
334348

335349
return true;

0 commit comments

Comments
 (0)