Skip to content

Commit

Permalink
Simplifying WAM errors (#280)
Browse files Browse the repository at this point in the history
* Changed start error check

* WAM Error Fix

* Added resource caller

* make dev box instance actually aware that its in the saving state

* PR comments

---------

Co-authored-by: Huzaifa Danish <modanish@microsoft.com>
Co-authored-by: Branden Bonaby <bbonaby@microsoft.com>
  • Loading branch information
3 people authored Oct 4, 2024
1 parent d071938 commit 732a343
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 16 deletions.
6 changes: 6 additions & 0 deletions src/AzureExtension/DevBox/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ public static class DevBoxPowerStates

public const string DevBoxUnableToCheckTaskbarPinning = "DevBox_UnableToCheckTaskbarPinningStatus";

public const string DevBoxWAMError1 = "DevBox_WAMError1";

public const string DevBoxWAMError2 = "DevBox_WAMError2";

public const string DevBoxWAMErrorRefer = "DevBox_WAMErrorRefer";

/// <summary>
/// Resource key for the error message to show with the log location for the configuration flow.
/// </summary>
Expand Down
22 changes: 14 additions & 8 deletions src/AzureExtension/DevBox/DevBoxInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public class DevBoxInstance : IComputeSystem, IComputeSystem2

public event TypedEventHandler<IComputeSystem, ComputeSystemState>? StateChanged;

private bool _isPinOperationInProgress;

public DevBoxInstance(
IDevBoxManagementService devBoxManagementService,
IDevBoxOperationWatcher devBoxOperationWatcher,
Expand Down Expand Up @@ -207,8 +209,10 @@ private ComputeSystemOperations GetOperations()
switch (state)
{
// Dev Box in process of being deleted
// or pinned/unpinned from start menu/taskbar.
case ComputeSystemState.Deleting:
case ComputeSystemState.Deleted:
case ComputeSystemState.Saving:
return ComputeSystemOperations.None;
case ComputeSystemState.Saved:
// Dev Box in hibernation
Expand Down Expand Up @@ -459,6 +463,11 @@ public ComputeSystemState GetState()

_log.Information($"Getting State for devBox: '{DisplayName}', Provisioning: {provisioningState}, Action: {actionState}, Power: {powerState}");

if (_isPinOperationInProgress)
{
return ComputeSystemState.Saving;
}

// This state is actually failed, but since ComputeSystemState doesn't have a failed state, we'll return unknown.
if (provisioningState == Constants.DevBoxProvisioningStates.Failed
|| provisioningState == Constants.DevBoxProvisioningStates.ProvisionedWithWarning)
Expand Down Expand Up @@ -710,6 +719,9 @@ public IAsyncOperation<ComputeSystemOperationResult> DoPinActionAsync(string loc
{
return Task.Run(() =>
{
_isPinOperationInProgress = true;
StateChanged?.Invoke(this, GetState());
try
{
var errorString = ValidateWindowsAppAndItsParameters();
Expand Down Expand Up @@ -738,6 +750,7 @@ public IAsyncOperation<ComputeSystemOperationResult> DoPinActionAsync(string loc
exitCode = process.ExitCode;
if (exitCode == ExitCodeSuccess)
{
_isPinOperationInProgress = false;
UpdateStateForUI();
return new ComputeSystemOperationResult();
}
Expand All @@ -749,6 +762,7 @@ public IAsyncOperation<ComputeSystemOperationResult> DoPinActionAsync(string loc
catch (Exception ex)
{
_log.Error(ex, $"Unable to perform the pinning action for DevBox: {DisplayName}");
_isPinOperationInProgress = false;
UpdateStateForUI();
return new ComputeSystemOperationResult(ex, Constants.OperationsDefaultErrorMsg, "Pinning action failed");
}
Expand All @@ -757,29 +771,21 @@ public IAsyncOperation<ComputeSystemOperationResult> DoPinActionAsync(string loc

public IAsyncOperation<ComputeSystemOperationResult> PinToStartMenuAsync()
{
// Since there is no 'Pinning' state we'll say that the state is saving
StateChanged?.Invoke(this, ComputeSystemState.Saving);
return DoPinActionAsync("startMenu", "pin");
}

public IAsyncOperation<ComputeSystemOperationResult> UnpinFromStartMenuAsync()
{
// Since there is no 'Unpinning' state we'll say that the state is saving
StateChanged?.Invoke(this, ComputeSystemState.Saving);
return DoPinActionAsync("startMenu", "unpin");
}

public IAsyncOperation<ComputeSystemOperationResult> PinToTaskbarAsync()
{
// Since there is no 'Pinning' state we'll say that the state is saving
StateChanged?.Invoke(this, ComputeSystemState.Saving);
return DoPinActionAsync("taskbar", "pin");
}

public IAsyncOperation<ComputeSystemOperationResult> UnpinFromTaskbarAsync()
{
// Since there is no 'Unpinning' state we'll say that the state is saving
StateChanged?.Invoke(this, ComputeSystemState.Saving);
return DoPinActionAsync("taskbar", "unpin");
}

Expand Down
22 changes: 22 additions & 0 deletions src/AzureExtension/DevBox/DevBoxProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ public IAsyncOperation<ComputeSystemsResult> GetComputeSystemsAsync(IDeveloperId
{
errorMessage = Resources.GetResource(Constants.NoDefaultUserFailKey);
}
else if (ex.Message.Contains("WAM Error"))
{
errorMessage = SimplifyWAMError(ex.Message);
}
else
{
errorMessage = Resources.GetResource(Constants.RetrievalFailKey, developerId.LoginId) + ex.Message;
Expand All @@ -191,6 +195,24 @@ public IAsyncOperation<ComputeSystemsResult> GetComputeSystemsAsync(IDeveloperId
}).AsAsyncOperation();
}

// Handle common WAM errors
// Reference: https://learn.microsoft.com/en-us/entra/msal/dotnet/advanced/exceptions/wam-errors
private string SimplifyWAMError(string errorMessage)
{
if (errorMessage.Contains("3399614467"))
{
return Constants.DevBoxWAMError1 + "\n" + Resources.GetResource(Constants.DevBoxWAMErrorRefer);
}
else if (errorMessage.Contains("3399614476"))
{
return Constants.DevBoxWAMError2 + "\n" + Resources.GetResource(Constants.DevBoxWAMErrorRefer);
}
else
{
return errorMessage + "\n" + Resources.GetResource(Constants.DevBoxWAMErrorRefer);
}
}

public ICreateComputeSystemOperation? CreateCreateComputeSystemOperation(IDeveloperId developerId, string inputJson)
{
_log.Information($"Attempting to create CreateComputeSystemOperation for {developerId.LoginId}");
Expand Down
12 changes: 4 additions & 8 deletions src/AzureExtension/DevBox/Helpers/WingetConfigWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,11 @@ private async Task HandleNonRunningState()
}

// Start the Dev Box
try
_log.Information("Starting the dev box to apply configuration");
var startResult = (await _devBox.StartAsync(string.Empty)).Result;
if (startResult.Status != ProviderOperationStatus.Success)
{
_log.Information("Starting the dev box to apply configuration");
var startResult = await _devBox.StartAsync(string.Empty);
}
catch (Exception ex)
{
_log.Error(ex, "Unable to start the dev box");
throw new InvalidOperationException(Resources.GetResource(DevBoxErrorStateKey, _devBox.DisplayName));
throw new InvalidOperationException(Resources.GetResource(DevBoxErrorStartKey, _devBox.DisplayName));
}

// Notify the user
Expand Down
12 changes: 12 additions & 0 deletions src/AzureExtension/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -734,4 +734,16 @@
<value>Finding your pull requests. This may take several minutes.</value>
<comment>Shown in Widget</comment>
</data>
<data name="DevBox_WAMError1" xml:space="preserve">
<value>Error : 3399614467. The user account has been deleted from the tenant directory. Ensure that the account with which the user tries to sign in is registered in Microsoft Entra ID.</value>
<comment>Simplified error messages for WAM error 3399614467</comment>
</data>
<data name="DevBox_WAMError2" xml:space="preserve">
<value>Error : 3399614476. Please refresh your multi-factor authentication. Account needs to be configured by the Microsoft Entra administrator with up-to-date MFA settings.</value>
<comment>Simplified error messages for WAM error 3399614476</comment>
</data>
<data name="DevBox_WAMErrorRefer" xml:space="preserve">
<value>For more details, please refer to https://learn.microsoft.com/en-us/entra/msal/dotnet/advanced/exceptions/wam-errors</value>
<comment>{Locked="https://learn.microsoft.com/en-us/entra/msal/dotnet/advanced/exceptions/wam-errors"} Redirect link to MS Learn page for additional info on WAM errors</comment>
</data>
</root>

0 comments on commit 732a343

Please sign in to comment.