Refactor VelopackApp exceptions

This commit is contained in:
Caelan Sayler
2024-01-11 14:49:27 +00:00
parent 72c8c790c0
commit c95ebc2833
3 changed files with 32 additions and 10 deletions

View File

@@ -80,20 +80,19 @@ namespace Velopack.Packaging
psi.AppendArgumentListSafe(new[] { "--veloapp-version" }, out var _);
var output = psi.Output(5000);
if (String.IsNullOrWhiteSpace(output)) {
throw new UserErrorException(
"Failed to verify VelopackApp (Exited with no output). " +
"Ensure you have add the startup code to your Program.Main(): VelopackApp.Build().Run(); and then re-compile your application.");
throw new VelopackAppVerificationException("Exited with no output");
}
var version = SemanticVersion.Parse(output.Trim());
if (version != VelopackRuntimeInfo.VelopackNugetVersion) {
Log.Warn($"VelopackApp version '{version}' does not match CLI version '{VelopackRuntimeInfo.VelopackNugetVersion}'.");
if (SemanticVersion.TryParse(output.Trim(), out var version)) {
if (version != VelopackRuntimeInfo.VelopackNugetVersion) {
Log.Warn($"VelopackApp version '{version}' does not match CLI version '{VelopackRuntimeInfo.VelopackNugetVersion}'.");
} else {
Log.Info($"VelopackApp version verified ({version}).");
}
} else {
Log.Info($"VelopackApp version verified ({version}).");
throw new VelopackAppVerificationException($"Failed to parse version: {output.Trim()}");
}
} catch (TimeoutException) {
throw new UserErrorException(
"Failed to verify VelopackApp (Timed out). " +
"Ensure you have add the startup code to your Program.Main(): VelopackApp.Build().Run(); and then re-compile your application.");
throw new VelopackAppVerificationException("Timed out");
}
var suffix = ReleaseEntryHelper.GetPkgSuffix(SupportedTargetOs, channel);

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
@@ -10,6 +11,7 @@ namespace Velopack.Packaging
/// <summary>
/// Denotes that an error has occurred for which a stack trace should not be printed.
/// </summary>
[ExcludeFromCodeCoverage]
public class UserErrorException : Exception
{
public UserErrorException()

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Velopack.Packaging
{
[ExcludeFromCodeCoverage]
public class VelopackAppVerificationException : UserErrorException
{
public VelopackAppVerificationException(string message)
: base(
$"Failed to verify VelopackApp ({message}). " +
$"Ensure you have added the startup code to the beginning of your Program.Main(): VelopackApp.Build().Run(); " +
$"and then re-compile/re-publish your application.")
{
}
}
}