From ef4442a002f9fdbfeafdee5b37416972336feb7d Mon Sep 17 00:00:00 2001 From: Eric Lloyd Date: Fri, 14 Sep 2018 09:33:33 -0700 Subject: [PATCH] Specialized Exception types --- src/Squirrel/ExceptionTypes.cs | 50 +++++++++++++++++++ src/Squirrel/Squirrel.csproj | 1 + src/Squirrel/UpdateManager.CheckForUpdates.cs | 8 +-- src/Squirrel/UpdateManager.cs | 2 +- 4 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 src/Squirrel/ExceptionTypes.cs diff --git a/src/Squirrel/ExceptionTypes.cs b/src/Squirrel/ExceptionTypes.cs new file mode 100644 index 000000000..2cd86bdb7 --- /dev/null +++ b/src/Squirrel/ExceptionTypes.cs @@ -0,0 +1,50 @@ +using System; + +namespace Squirrel +{ + /// + /// + /// Base class for Squirrel-originated exceptions. + /// + public abstract class SquirrelBaseException: Exception + { + protected SquirrelBaseException(string message) + : base(message) + { + } + } + + /// + /// Thrown when no Releases folder or RELEASES file is found at the specified location. + /// + public class SquirrelReleasesMissingException : SquirrelBaseException + { + public SquirrelReleasesMissingException(string message) + : base(message) + { + } + } + + /// + /// Thrown when the Releases\RELEASES file is empty or corrupt. + /// + public class SquirrelReleasesCorruptException: SquirrelBaseException + { + public SquirrelReleasesCorruptException(string message) + : base(message) + { + } + } + + /// + /// Thrown when Update.exe isn't found in the expected location. + /// + /// See https://github.com/Squirrel/Squirrel.Windows/blob/master/docs/using/debugging-updates.md for more information. + public class SquirrelNoUpdateException: SquirrelBaseException + { + public SquirrelNoUpdateException(string message) + : base(message) + { + } + } +} diff --git a/src/Squirrel/Squirrel.csproj b/src/Squirrel/Squirrel.csproj index 9769199ef..4fea080ad 100644 --- a/src/Squirrel/Squirrel.csproj +++ b/src/Squirrel/Squirrel.csproj @@ -84,6 +84,7 @@ + diff --git a/src/Squirrel/UpdateManager.CheckForUpdates.cs b/src/Squirrel/UpdateManager.CheckForUpdates.cs index 226494d30..9a4f63ac7 100644 --- a/src/Squirrel/UpdateManager.CheckForUpdates.cs +++ b/src/Squirrel/UpdateManager.CheckForUpdates.cs @@ -92,7 +92,7 @@ public async Task CheckForUpdate( "The directory {0} does not exist, something is probably broken with your application", updateUrlOrPath); - throw new Exception(message); + throw new SquirrelReleasesMissingException(message); } var fi = new FileInfo(Path.Combine(updateUrlOrPath, "RELEASES")); @@ -105,7 +105,7 @@ public async Task CheckForUpdate( var packages = (new DirectoryInfo(updateUrlOrPath)).GetFiles("*.nupkg"); if (packages.Length == 0) { - throw new Exception(message); + throw new SquirrelReleasesMissingException(message); } // NB: Create a new RELEASES file since we've got a directory of packages @@ -122,7 +122,7 @@ public async Task CheckForUpdate( progress(66); if (!remoteReleases.Any()) { - throw new Exception("Remote release File is empty or corrupted"); + throw new SquirrelReleasesCorruptException("Remote release File is empty or corrupted"); } ret = determineUpdateInfo(localReleases, remoteReleases, ignoreDeltaUpdates); @@ -149,7 +149,7 @@ UpdateInfo determineUpdateInfo(IEnumerable localReleases, IEnumera if (remoteReleases == null) { this.Log().Warn("Release information couldn't be determined due to remote corrupt RELEASES file"); - throw new Exception("Corrupt remote RELEASES file"); + throw new SquirrelReleasesCorruptException("Corrupt remote RELEASES file"); } var latestFullRelease = Utility.FindCurrentVersion(remoteReleases); diff --git a/src/Squirrel/UpdateManager.cs b/src/Squirrel/UpdateManager.cs index 6e9d59f59..13b47cad0 100644 --- a/src/Squirrel/UpdateManager.cs +++ b/src/Squirrel/UpdateManager.cs @@ -310,7 +310,7 @@ static string getUpdateExe() var updateDotExe = Path.Combine(Path.GetDirectoryName(assembly.Location), "..\\Update.exe"); var target = new FileInfo(updateDotExe); - if (!target.Exists) throw new Exception("Update.exe not found, not a Squirrel-installed app?"); + if (!target.Exists) throw new SquirrelNoUpdateException("Update.exe not found, not a Squirrel-installed app?"); return target.FullName; } }