Skip to content

Commit

Permalink
Implement new bootstrapper error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaboxer committed Sep 8, 2024
1 parent cd411e3 commit dd568fa
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 101 deletions.
3 changes: 1 addition & 2 deletions Bloxstrap/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ public static void FinalizeExceptionHandling(Exception ex, bool log = true)

_showingExceptionDialog = true;

if (!LaunchSettings.QuietFlag.Active)
Frontend.ShowExceptionDialog(ex);
Frontend.ShowExceptionDialog(ex);

Terminate(ErrorCode.ERROR_INSTALL_FAILURE);
}
Expand Down
71 changes: 45 additions & 26 deletions Bloxstrap/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,35 @@ private void UpdateProgressBar()

Dialog.ProgressValue = progressValue;
}

private void HandleConnectionError(Exception exception)
{
_noConnection = true;

string message = Strings.Dialog_Connectivity_Preventing;

if (exception.GetType() == typeof(AggregateException))
exception = exception.InnerException!;

if (exception.GetType() == typeof(HttpRequestException))
message = String.Format(Strings.Dialog_Connectivity_RobloxDown, "[status.roblox.com](https://status.roblox.com)");
else if (exception.GetType() == typeof(TaskCanceledException))
message = Strings.Dialog_Connectivity_TimedOut;

if (_mustUpgrade)
message += $"\n\n{Strings.Dialog_Connectivity_RobloxUpgradeNeeded}\n\n{Strings.Dialog_Connectivity_TryAgainLater}";
else
message += $"\n\n{Strings.Dialog_Connectivity_RobloxUpgradeSkip}";

Frontend.ShowConnectivityDialog(
String.Format(Strings.Dialog_Connectivity_UnableToConnect, "Roblox"),
message,
_mustUpgrade ? MessageBoxImage.Error : MessageBoxImage.Warning,
exception);

if (_mustUpgrade)
App.Terminate(ErrorCode.ERROR_CANCELLED);
}

public async Task Run()
{
Expand All @@ -101,24 +130,7 @@ public async Task Run()

if (connectionResult is not null)
{
App.Logger.WriteLine(LOG_IDENT, "Connectivity check failed!");
App.Logger.WriteException(LOG_IDENT, connectionResult);

string message = Strings.Bootstrapper_Connectivity_Preventing;

if (connectionResult.GetType() == typeof(HttpResponseException))
message = Strings.Bootstrapper_Connectivity_RobloxDown;
else if (connectionResult.GetType() == typeof(TaskCanceledException))
message = Strings.Bootstrapper_Connectivity_TimedOut;
else if (connectionResult.GetType() == typeof(AggregateException))
connectionResult = connectionResult.InnerException!;

// TODO: handle update skip
Frontend.ShowConnectivityDialog(Strings.Dialog_Connectivity_UnableToConnect, message, connectionResult);

App.Terminate(ErrorCode.ERROR_CANCELLED);

return;
HandleConnectionError(connectionResult);
}

#if !DEBUG || DEBUG_UPDATER
Expand Down Expand Up @@ -159,8 +171,17 @@ public async Task Run()
App.State.Load();
}

// TODO: handle exception and update skip
await GetLatestVersionInfo();
if (!_noConnection)
{
try
{
await GetLatestVersionInfo();
}
catch (Exception ex)
{
HandleConnectionError(ex);
}
}

if (!_noConnection)
{
Expand All @@ -172,7 +193,6 @@ public async Task Run()
await ApplyModifications();
}


// check if launch uri is set to our bootstrapper
// this doesn't go under register, so we check every launch
// just in case the stock bootstrapper changes it back
Expand Down Expand Up @@ -232,15 +252,14 @@ private async Task GetLatestVersionInfo()
{
clientVersion = await RobloxDeployment.GetInfo(channel, AppData.BinaryType);
}
catch (HttpResponseException ex)
catch (HttpRequestException ex)
{
if (ex.ResponseMessage.StatusCode
is not HttpStatusCode.Unauthorized
if (ex.StatusCode is not HttpStatusCode.Unauthorized
and not HttpStatusCode.Forbidden
and not HttpStatusCode.NotFound)
throw;

App.Logger.WriteLine(LOG_IDENT, $"Changing channel from {channel} to {RobloxDeployment.DefaultChannel} because HTTP {(int)ex.ResponseMessage.StatusCode}");
App.Logger.WriteLine(LOG_IDENT, $"Changing channel from {channel} to {RobloxDeployment.DefaultChannel} because HTTP {(int)ex.StatusCode}");

channel = RobloxDeployment.DefaultChannel;
clientVersion = await RobloxDeployment.GetInfo(channel, AppData.BinaryType);
Expand Down Expand Up @@ -624,7 +643,6 @@ private async Task UpgradeRoblox()
SetStatus(Strings.Bootstrapper_Status_Configuring);
}

// TODO: handle faulted tasks
await Task.WhenAll(extractionTasks);

App.Logger.WriteLine(LOG_IDENT, "Writing AppSettings.xml...");
Expand Down Expand Up @@ -1011,6 +1029,7 @@ private async Task DownloadPackage(Package package)
Frontend.ShowConnectivityDialog(
Strings.Dialog_Connectivity_UnableToDownload,
String.Format(Strings.Dialog_Connectivity_UnableToDownloadReason, "[https://github.com/pizzaboxer/bloxstrap/wiki/Bloxstrap-is-unable-to-download-Roblox](https://github.com/pizzaboxer/bloxstrap/wiki/Bloxstrap-is-unable-to-download-Roblox)"),
MessageBoxImage.Error,
ex
);

Expand Down
19 changes: 0 additions & 19 deletions Bloxstrap/Exceptions/HttpResponseException.cs

This file was deleted.

92 changes: 64 additions & 28 deletions Bloxstrap/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 19 additions & 7 deletions Bloxstrap/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@
<data name="Bootstrapper.ConfirmLaunch" xml:space="preserve">
<value>Roblox is currently running, and launching another instance will close it. Are you sure you want to continue launching?</value>
</data>
<data name="Bootstrapper.Connectivity.Preventing" xml:space="preserve">
<value>It's possible that something is preventing Bloxstrap from connecting to the internet. Please check and try again.</value>
<data name="Dialog.Connectivity.Preventing" xml:space="preserve">
<value>Something is likely preventing Bloxstrap from connecting to the internet.</value>
</data>
<data name="Bootstrapper.Connectivity.RobloxDown" xml:space="preserve">
<value>Roblox may be down right now. See status.roblox.com for more information. Please try again later.</value>
<data name="Dialog.Connectivity.RobloxDown" xml:space="preserve">
<value>Roblox may be down right now. See {0} for more information.</value>
</data>
<data name="Bootstrapper.Connectivity.TimedOut" xml:space="preserve">
<value>Bloxstrap timed out when trying to connect to three different Roblox deployment mirrors, indicating a poor internet connection. Please try again later.</value>
<data name="Dialog.Connectivity.TimedOut" xml:space="preserve">
<value>The connection timed out, which could indicate a poor internet connection or a firewall block.</value>
</data>
<data name="Bootstrapper.EmojiPresetFetchFailed" xml:space="preserve">
<value>Could not apply the {0} emoji mod preset because of a network error. To try again, please reconfigure the option in the Bloxstrap Menu.</value>
Expand Down Expand Up @@ -294,7 +294,7 @@ Click for more information</value>
<value>Connectivity error</value>
</data>
<data name="Dialog.Connectivity.UnableToConnect" xml:space="preserve">
<value>Bloxstrap is unable to connect to Roblox</value>
<value>Bloxstrap is unable to connect to {0}</value>
</data>
<data name="Dialog.Exception.CopyLogContents" xml:space="preserve">
<value>Copy log contents</value>
Expand Down Expand Up @@ -1171,4 +1171,16 @@ Are you sure you want to continue?</value>
<data name="ActivityWatcher.LocationQueryFailed" xml:space="preserve">
<value>Failed to query server location.</value>
</data>
<data name="Dialog.Connectivity.ServiceDown" xml:space="preserve">
<value>{0} may be down right now.</value>
</data>
<data name="Dialog.Connectivity.TryAgainLater" xml:space="preserve">
<value>Please try again later.</value>
</data>
<data name="Dialog.Connectivity.RobloxUpgradeSkip" xml:space="preserve">
<value>For this launch, Roblox will not be checked for upgrades, and changes to mods will not be applied.</value>
</data>
<data name="Dialog.Connectivity.RobloxUpgradeNeeded" xml:space="preserve">
<value>Because Roblox needs to be installed or upgraded, Bloxstrap cannot continue.</value>
</data>
</root>
7 changes: 3 additions & 4 deletions Bloxstrap/RobloxDeployment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public static class RobloxDeployment
{
var response = await App.HttpClient.GetAsync($"{url}/versionStudio", token);

if (!response.IsSuccessStatusCode)
throw new HttpResponseException(response);
response.EnsureSuccessStatusCode();

// versionStudio is the version hash for the last MFC studio to be deployed.
// the response body should always be "version-012732894899482c".
Expand Down Expand Up @@ -151,14 +150,14 @@ public static async Task<ClientVersion> GetInfo(string channel, string binaryTyp

try
{
clientVersion = await Http.GetJson<ClientVersion>($"https://clientsettingscdn.roblox.com/{path}");
clientVersion = await Http.GetJson<ClientVersion>("https://clientsettingscdn.roblox.com" + path);
}
catch (Exception ex)
{
App.Logger.WriteLine(LOG_IDENT, "Failed to contact clientsettingscdn! Falling back to clientsettings...");
App.Logger.WriteException(LOG_IDENT, ex);

clientVersion = await Http.GetJson<ClientVersion>($"https://clientsettings.roblox.com/{path}");
clientVersion = await Http.GetJson<ClientVersion>("https://clientsettings.roblox.com" + path);
}

// check if channel is behind LIVE
Expand Down
11 changes: 1 addition & 10 deletions Bloxstrap/RobloxFastFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,7 @@ private async Task Fetch()

string rawResponse = await response.Content.ReadAsStringAsync();

if (!response.IsSuccessStatusCode)
{
App.Logger.WriteLine(logIndent,
"Failed to fetch client settings!\r\n" +
$"\tStatus code: {response.StatusCode}\r\n" +
$"\tResponse: {rawResponse}"
);

throw new HttpResponseException(response);
}
response.EnsureSuccessStatusCode();

var clientSettings = JsonSerializer.Deserialize<ClientFlagSettings>(rawResponse);

Expand Down
3 changes: 2 additions & 1 deletion Bloxstrap/UI/Elements/Dialogs/ConnectivityDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Width="480"
MinHeight="0"
SizeToContent="Height"
Title="{x:Static resources:Strings.Dialog_Connectivity_Title}"
Background="{ui:ThemeResource ApplicationBackgroundBrush}"
ExtendsContentIntoTitleBar="True"
WindowStartupLocation="CenterScreen">
Expand All @@ -29,7 +30,7 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Width="32" Height="32" Margin="0,0,15,0" VerticalAlignment="Top" RenderOptions.BitmapScalingMode="HighQuality" Source="pack://application:,,,/Resources/MessageBox/Error.png" />
<Image x:Name="IconImage" Grid.Column="0" Width="32" Height="32" Margin="0,0,15,0" VerticalAlignment="Top" RenderOptions.BitmapScalingMode="HighQuality" Source="pack://application:,,,/Resources/MessageBox/Error.png" />
<StackPanel Grid.Column="1">
<TextBlock x:Name="TitleTextBlock" Text="? is unable to connect to ?" FontSize="18" Foreground="{DynamicResource TextFillColorPrimaryBrush}" />
<controls:MarkdownTextBlock x:Name="DescriptionTextBlock" MarkdownText="?" Margin="0,16,0,0" TextWrapping="Wrap" Foreground="{DynamicResource TextFillColorPrimaryBrush}" />
Expand Down
Loading

0 comments on commit dd568fa

Please sign in to comment.