Skip to content

Log the response text if available when exception is thrown while processing a user query #338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2025
Merged
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
26 changes: 20 additions & 6 deletions shell/agents/Microsoft.Azure.Agent/AzureAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ public async Task RefreshChatAsync(IShell shell, bool force)
{
IHost host = shell.Host;
CancellationToken cancellationToken = shell.CancellationToken;

_copilotResponse = null;
ResetArgumentPlaceholder();

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

_copilotResponse = null;
ResetArgumentPlaceholder();

if (_turnsLeft is 0)
{
host.WriteLine("\nSorry, you've reached the maximum length of a conversation. Please run '/refresh' to start a new conversation.\n");
Expand Down Expand Up @@ -243,8 +248,6 @@ public async Task<bool> ChatAsync(string input, IShell shell)

if (_copilotResponse.ChunkReader is null)
{
ResetArgumentPlaceholder();

if (_copilotResponse.IsError)
{
string errorMessage = _copilotResponse.Text;
Expand Down Expand Up @@ -325,11 +328,22 @@ public async Task<bool> ChatAsync(string input, IShell shell)

Telemetry.Trace(AzTrace.Chat(_copilotResponse));
}
catch (Exception ex) when (ex is TokenRequestException or ConnectionDroppedException)
catch (Exception ex)
{
host.WriteErrorLine(ex.Message);
host.WriteErrorLine("Please run '/refresh' to start a new chat session and try again.");
return false;
if (ex is TokenRequestException or ConnectionDroppedException)
{
host.WriteErrorLine(ex.Message);
host.WriteErrorLine("Please run '/refresh' to start a new chat session and try again.");
return false;
}

Log.Error(ex, "Exception thrown when processing the query '{0}'", input);
if (_copilotResponse?.Text is not null)
{
Log.Error("Response text:\n{0}", _copilotResponse.Text);
}

throw;
}

return true;
Expand Down