Browse Source

Improved error handling for package install

pull/55/head
Ionite 1 year ago
parent
commit
13af97104c
No known key found for this signature in database
  1. 4
      StabilityMatrix.Avalonia/Helpers/UnixPrerequisiteHelper.cs
  2. 120
      StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs
  3. 13
      StabilityMatrix.Core/Models/Packages/VladAutomatic.cs

4
StabilityMatrix.Avalonia/Helpers/UnixPrerequisiteHelper.cs

@ -130,6 +130,10 @@ public class UnixPrerequisiteHelper : IPrerequisiteHelper
var result = await ProcessRunner.RunBashCommand(command, workingDirectory ?? "");
if (result.ExitCode != 0)
{
Logger.Error("Git command [{Command}] failed with exit code " +
"{ExitCode}:\n{StdOut}\n{StdErr}",
command, result.ExitCode, result.StandardOutput, result.StandardError);
throw new ProcessException($"Git command [{command}] failed with exit code" +
$" {result.ExitCode}:\n{result.StandardOutput}\n{result.StandardError}");
}

120
StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs

@ -15,7 +15,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using FluentAvalonia.UI.Controls;
using NLog;
using Octokit;
using StabilityMatrix.Avalonia.Controls;
using StabilityMatrix.Avalonia.Services;
using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Helper.Factory;
@ -26,8 +26,6 @@ using StabilityMatrix.Core.Models.Progress;
using StabilityMatrix.Core.Processes;
using StabilityMatrix.Core.Python;
using StabilityMatrix.Core.Services;
using Notification = Avalonia.Controls.Notifications.Notification;
using PackageVersion = StabilityMatrix.Core.Models.PackageVersion;
namespace StabilityMatrix.Avalonia.ViewModels.Dialogs;
@ -152,6 +150,19 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
"Success", NotificationType.Success));
OnPrimaryButtonClick();
}
else
{
var ex = result.Exception!;
Logger.Error(ex, $"Error installing package: {ex}");
var dialog = new BetterContentDialog
{
Title = "Error installing package",
Content = ex.ToString(),
CloseButtonText = "Close"
};
await dialog.ShowAsync();
}
}
private async Task ActuallyInstall()
@ -163,62 +174,79 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
return;
}
await InstallGitIfNecessary();
SelectedPackage.InstallLocation = Path.Combine(
settingsManager.LibraryDir, "Packages", InstallName);
if (!PyRunner.PipInstalled || !PyRunner.VenvInstalled)
try
{
InstallProgress.Text = "Installing dependencies...";
InstallProgress.IsIndeterminate = true;
await pyRunner.Initialize();
await InstallGitIfNecessary();
if (!PyRunner.PipInstalled)
SelectedPackage.InstallLocation = Path.Combine(
settingsManager.LibraryDir, "Packages", InstallName);
if (!PyRunner.PipInstalled || !PyRunner.VenvInstalled)
{
await pyRunner.SetupPip();
InstallProgress.Text = "Installing dependencies...";
InstallProgress.IsIndeterminate = true;
await pyRunner.Initialize();
if (!PyRunner.PipInstalled)
{
await pyRunner.SetupPip();
}
if (!PyRunner.VenvInstalled)
{
await pyRunner.InstallPackage("virtualenv");
}
}
if (!PyRunner.VenvInstalled)
string version;
if (IsReleaseMode)
{
await pyRunner.InstallPackage("virtualenv");
version = SelectedVersion?.TagName ??
throw new NullReferenceException("Selected version is null");
await DownloadPackage(version, false);
}
}
else
{
version = SelectedCommit?.Sha ??
throw new NullReferenceException("Selected commit is null");
var version = IsReleaseMode
? await DownloadPackage(SelectedVersion!.TagName, false)
: await DownloadPackage(SelectedCommit!.Sha, true);
await DownloadPackage(version, true);
}
await InstallPackage();
await InstallPackage();
InstallProgress.Text = "Setting up shared folder links...";
sharedFolders.SetupLinksForPackage(SelectedPackage, SelectedPackage.InstallLocation);
InstallProgress.Text = "Setting up shared folder links...";
sharedFolders.SetupLinksForPackage(SelectedPackage, SelectedPackage.InstallLocation);
InstallProgress.Text = "Done";
InstallProgress.IsIndeterminate = false;
InstallProgress.Value = 100;
EventManager.Instance.OnGlobalProgressChanged(100);
InstallProgress.Text = "Done";
InstallProgress.IsIndeterminate = false;
InstallProgress.Value = 100;
EventManager.Instance.OnGlobalProgressChanged(100);
var branch = SelectedVersionType == PackageVersionType.GithubRelease ?
null : SelectedVersion!.TagName;
var branch = SelectedVersionType == PackageVersionType.GithubRelease ?
null : SelectedVersion!.TagName;
var package = new InstalledPackage
var package = new InstalledPackage
{
DisplayName = InstallName,
LibraryPath = Path.Combine("Packages", InstallName),
Id = Guid.NewGuid(),
PackageName = SelectedPackage.Name,
PackageVersion = version,
DisplayVersion = GetDisplayVersion(version, branch),
InstalledBranch = branch,
LaunchCommand = SelectedPackage.LaunchCommand,
LastUpdateCheck = DateTimeOffset.Now
};
await using var st = settingsManager.BeginTransaction();
st.Settings.InstalledPackages.Add(package);
st.Settings.ActiveInstalledPackage = package.Id;
}
finally
{
DisplayName = InstallName,
LibraryPath = Path.Combine("Packages", InstallName),
Id = Guid.NewGuid(),
PackageName = SelectedPackage.Name,
PackageVersion = version,
DisplayVersion = GetDisplayVersion(version, branch),
InstalledBranch = branch,
LaunchCommand = SelectedPackage.LaunchCommand,
LastUpdateCheck = DateTimeOffset.Now
};
await using var st = settingsManager.BeginTransaction();
st.Settings.InstalledPackages.Add(package);
st.Settings.ActiveInstalledPackage = package.Id;
InstallProgress.Value = 0;
InstallProgress.IsIndeterminate = false;
InstallProgress.Value = 0;
InstallProgress.IsIndeterminate = false;
}
}
private static string GetDisplayVersion(string version, string? branch)

13
StabilityMatrix.Core/Models/Packages/VladAutomatic.cs

@ -4,6 +4,7 @@ using System.Text.RegularExpressions;
using NLog;
using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Helper.Cache;
using StabilityMatrix.Core.Models.FileInterfaces;
using StabilityMatrix.Core.Models.Progress;
using StabilityMatrix.Core.Processes;
using StabilityMatrix.Core.Python;
@ -181,11 +182,15 @@ public class VladAutomatic : BaseGitPackage
{
progress?.Report(new ProgressReport(0.1f, message: "Downloading package...", isIndeterminate: true, type: ProgressType.Download));
Directory.CreateDirectory(InstallLocation);
var installDir = new DirectoryPath(InstallLocation);
installDir.Create();
await PrerequisiteHelper.RunGit(null, "clone", "https://github.com/vladmandic/automatic",
InstallLocation);
await PrerequisiteHelper.RunGit(workingDirectory: InstallLocation, "checkout", version);
await PrerequisiteHelper.RunGit(
installDir.Parent ?? "", "clone", "https://github.com/vladmandic/automatic", installDir.Name)
.ConfigureAwait(false);
await PrerequisiteHelper.RunGit(
InstallLocation, "checkout", version).ConfigureAwait(false);
return version;
}

Loading…
Cancel
Save