Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specialized Exception types #1387

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/Squirrel/ExceptionTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;

namespace Squirrel
{
/// <inheritdoc />
/// <summary>
/// Base class for Squirrel-originated exceptions.
/// </summary>
public abstract class SquirrelBaseException: Exception
{
protected SquirrelBaseException(string message)
: base(message)
{
}
}

/// <summary>
/// Thrown when no Releases folder or RELEASES file is found at the specified location.
/// </summary>
public class SquirrelReleasesMissingException : SquirrelBaseException
{
public SquirrelReleasesMissingException(string message)
: base(message)
{
}
}

/// <summary>
/// Thrown when the Releases\RELEASES file is empty or corrupt.
/// </summary>
public class SquirrelReleasesCorruptException: SquirrelBaseException
{
public SquirrelReleasesCorruptException(string message)
: base(message)
{
}
}

/// <summary>
/// Thrown when Update.exe isn't found in the expected location.
/// </summary>
/// <remarks>See https://github.com/Squirrel/Squirrel.Windows/blob/master/docs/using/debugging-updates.md for more information.</remarks>
public class SquirrelNoUpdateException: SquirrelBaseException
{
public SquirrelNoUpdateException(string message)
: base(message)
{
}
}
}
1 change: 1 addition & 0 deletions src/Squirrel/Squirrel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<Compile Include="ContentType.cs" />
<Compile Include="DeltaPackage.cs" />
<Compile Include="EnumerableExtensions.cs" />
<Compile Include="ExceptionTypes.cs" />
<Compile Include="FileDownloader.cs" />
<Compile Include="IUpdateManager.cs" />
<Compile Include="MarkdownSharp.cs" />
Expand Down
8 changes: 4 additions & 4 deletions src/Squirrel/UpdateManager.CheckForUpdates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public async Task<UpdateInfo> 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"));
Expand All @@ -110,7 +110,7 @@ public async Task<UpdateInfo> 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
Expand All @@ -127,7 +127,7 @@ public async Task<UpdateInfo> 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(intention, localReleases, remoteReleases, ignoreDeltaUpdates);
Expand All @@ -154,7 +154,7 @@ UpdateInfo determineUpdateInfo(UpdaterIntention intention, IEnumerable<ReleaseEn

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);
Expand Down
2 changes: 1 addition & 1 deletion src/Squirrel/UpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down