Skip to content

Commit 68e21a3

Browse files
Merge branch 'master' into users/rishabhmalikMS/verboseLogsKnobUpdate
2 parents 18aee79 + abfc608 commit 68e21a3

File tree

17 files changed

+71
-17
lines changed

17 files changed

+71
-17
lines changed

src/Agent.Listener/Configuration.Windows/AutoLogonManager.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,26 @@ private void RestartBasedOnUserInput(CommandSettings command)
208208
//ExecuteAsync API of ProcessInvoker waits for the process to exit
209209
var args = $@"-r -t 15 -c ""{msg}""";
210210
Trace.Info($"Shutdown.exe path: {shutdownExePath}. Arguments: {args}");
211-
Process.Start(shutdownExePath, $@"{args}");
211+
212+
try
213+
{
214+
Process.Start(shutdownExePath, $@"{args}");
215+
}
216+
catch (System.ComponentModel.Win32Exception w32Ex)
217+
{
218+
Trace.Error($"Failed to start shutdown process: Win32 error {w32Ex.NativeErrorCode}: {w32Ex.Message}");
219+
_terminal.WriteError($"Failed to restart machine automatically. Please restart manually. Error: {w32Ex.Message}");
220+
}
221+
catch (FileNotFoundException fnfEx)
222+
{
223+
Trace.Error($"Shutdown executable not found at '{shutdownExePath}': {fnfEx.Message}");
224+
_terminal.WriteError($"Cannot find shutdown.exe. Please restart machine manually.");
225+
}
226+
catch (Exception ex)
227+
{
228+
Trace.Error($"Unexpected error starting shutdown process: {ex.Message} {ex}");
229+
_terminal.WriteError($"Failed to restart machine automatically. Please restart manually. Error: {ex.Message}");
230+
}
212231
}
213232
else
214233
{

src/Agent.Listener/Configuration/ConfigurationProvider.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,16 @@ private async Task<string> GetAzureSubscriptionIdAsync()
369369
azureSubscriptionId = string.Empty;
370370
}
371371
}
372+
catch (HttpRequestException httpEx)
373+
{
374+
azureSubscriptionId = string.Empty;
375+
Trace.Info($"HTTP error accessing Azure IMDS: {httpEx.Message}");
376+
}
377+
catch (TaskCanceledException tcEx) when (tcEx.InnerException is System.TimeoutException)
378+
{
379+
azureSubscriptionId = string.Empty;
380+
Trace.Info($"Timeout accessing Azure IMDS (not running on Azure): {tcEx.Message}");
381+
}
372382
catch (SocketException ex)
373383
{
374384
azureSubscriptionId = string.Empty;
@@ -379,6 +389,7 @@ private async Task<string> GetAzureSubscriptionIdAsync()
379389
// An exception will be thrown if the Agent Machine is a non-Azure VM.
380390
azureSubscriptionId = string.Empty;
381391
Trace.Info($"GetAzureSubscriptionId ex: {ex.Message}");
392+
Trace.Info(ex.ToString());
382393
}
383394
}
384395

src/Agent.Listener/JobDispatcher.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,7 @@ await processChannel.SendAsync(
11931193
catch (Exception ex)
11941194
{
11951195
Trace.Warning($"Failed to send flush logs request to worker: {ex.Message}");
1196+
Trace.Warning(ex.ToString());
11961197
}
11971198

11981199
// Now wait for the additional 1 minute log flushing period

src/Agent.Listener/MessageListener.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.VisualStudio.Services.Common;
99
using System;
1010
using System.Collections.Generic;
11+
using System.Net.Http;
1112
using System.Net.Sockets;
1213
using System.Threading;
1314
using System.Threading.Tasks;

src/Agent.Listener/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ private static async Task<int> MainAsync(IHostContext context, string[] args)
6868
{
6969
terminal.WriteError(StringUtil.Loc("ErrorOccurred", e.Message));
7070
trace.Error(StringUtil.Format($"Directory permission validation failed - insufficient permissions - {0}", e.Message));
71+
trace.Error(e);
7172
return Constants.Agent.ReturnCode.TerminatedError;
7273
}
7374

src/Agent.Sdk/ProcessInvoker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ internal protected virtual async Task CancelAndKillProcessTree(bool killProcessO
462462
// Store proc reference locally to prevent race conditions with Dispose()
463463
Process proc = _proc;
464464
ArgUtil.NotNull(proc, nameof(_proc));
465-
465+
466466
if (!killProcessOnCancel)
467467
{
468468
bool sigint_succeed = await SendSIGINT(SigintTimeout);

src/Agent.Worker/ExecutionContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ public void InitializeJob(Pipelines.AgentJobRequestMessage message, Cancellation
562562
catch (Exception ex)
563563
{
564564
Trace.Warning($"Unable to generate workspace ID: {ex.Message}");
565+
Trace.Warning(ex.ToString());
565566
}
566567
}
567568

src/Agent.Worker/GitManager.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,29 @@ public async Task DownloadAsync(IExecutionContext executionContext, string versi
7979
}
8080
catch (OperationCanceledException) when (executionContext.CancellationToken.IsCancellationRequested)
8181
{
82-
Trace.Info($"Git download has been cancelled.");
82+
Trace.Info("Git download cancelled by user");
83+
throw;
84+
}
85+
catch (UnauthorizedAccessException uaEx)
86+
{
87+
Trace.Error($"Access denied writing Git executable to '{downloadGitPath}'");
88+
Trace.Error(uaEx);
8389
throw;
8490
}
8591
catch (Exception ex)
8692
{
8793
retryCount++;
88-
Trace.Info("Failed to download Git");
94+
Trace.Info($"Git download failed (attempt {retryCount})");
8995
Trace.Error(ex);
9096

91-
if (retryCount > retryLimit)
97+
if (retryCount >= retryLimit)
9298
{
93-
Trace.Info($"Retry limit to download Git has been reached.");
94-
break;
95-
}
96-
else
97-
{
98-
Trace.Info("Retry Git download in 10 seconds.");
99-
await Task.Delay(retryDelay, executionContext.CancellationToken);
99+
Trace.Error($"Failed to download Git after {retryLimit} attempts");
100+
throw;
100101
}
102+
103+
Trace.Info($"Retry Git download in {retryDelay / 1000} seconds");
104+
await Task.Delay(retryDelay, executionContext.CancellationToken);
101105
}
102106
}
103107

src/Agent.Worker/Handlers/PowerShellExeHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public async Task RunAsync()
118118
catch (Exception ex)
119119
{
120120
Trace.Info($"Unable to determine whether the script file is rooted: {ex.Message}");
121+
Trace.Info(ex.ToString());
121122
}
122123

123124
Trace.Info($"Script file is rooted: {isScriptFileRooted}");

src/Agent.Worker/Handlers/ProcessHandler/ProcessHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public async Task RunAsync()
5959
catch (Exception ex)
6060
{
6161
Trace.Info($"Unable to determine whether the command is rooted: {ex.Message}");
62+
Trace.Info(ex.ToString());
6263
}
6364

6465
Trace.Info($"Command is rooted: {isCommandRooted}");

0 commit comments

Comments
 (0)