Skip to content

Commit c27556c

Browse files
committed
(maint) Changed exceptions types to be more specific
1 parent de010e9 commit c27556c

File tree

4 files changed

+76
-5
lines changed

4 files changed

+76
-5
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// -----------------------------------------------------------------------
2+
// <copyright file="InvalidStateException.cs" company="GitTools Contributors">
3+
// Copyright (c) 2015 - Present - GitTools Contributors
4+
// </copyright>
5+
// -----------------------------------------------------------------------
6+
7+
namespace GitReleaseManager.Core.Exceptions
8+
{
9+
using System;
10+
11+
[Serializable]
12+
public class InvalidStateException : Exception
13+
{
14+
public InvalidStateException()
15+
{
16+
}
17+
18+
public InvalidStateException(string message)
19+
: base(message)
20+
{
21+
}
22+
23+
public InvalidStateException(string message, Exception inner)
24+
: base(message, inner)
25+
{
26+
}
27+
28+
protected InvalidStateException(
29+
System.Runtime.Serialization.SerializationInfo info,
30+
System.Runtime.Serialization.StreamingContext context)
31+
: base(info, context)
32+
{
33+
}
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// -----------------------------------------------------------------------
2+
// <copyright file="MissingReleaseException.cs" company="GitTools Contributors">
3+
// Copyright (c) 2015 - Present - GitTools Contributors
4+
// </copyright>
5+
// -----------------------------------------------------------------------
6+
7+
namespace GitReleaseManager.Core.Exceptions
8+
{
9+
using System;
10+
11+
[Serializable]
12+
public class MissingReleaseException : Exception
13+
{
14+
public MissingReleaseException()
15+
{
16+
}
17+
18+
public MissingReleaseException(string message)
19+
: base(message)
20+
{
21+
}
22+
23+
public MissingReleaseException(string message, Exception inner)
24+
: base(message, inner)
25+
{
26+
}
27+
28+
protected MissingReleaseException(
29+
System.Runtime.Serialization.SerializationInfo info,
30+
System.Runtime.Serialization.StreamingContext context)
31+
: base(info, context)
32+
{
33+
}
34+
}
35+
}

Source/GitReleaseManager/GitHubProvider.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace GitReleaseManager.Core
1818
using System.Threading.Tasks;
1919
using AutoMapper;
2020
using GitReleaseManager.Core.Configuration;
21+
using GitReleaseManager.Core.Exceptions;
2122
using GitReleaseManager.Core.Extensions;
2223
using Octokit;
2324
using Serilog;
@@ -159,7 +160,7 @@ public async Task<Release> CreateReleaseFromMilestone(string owner, string repos
159160

160161
if (!release.Draft)
161162
{
162-
throw new Exception("Release is not in draft state, so not updating.");
163+
throw new InvalidOperationException("Release is not in draft state, so not updating.");
163164
}
164165

165166
var releaseUpdate = release.ToUpdate();
@@ -202,12 +203,12 @@ public async Task DiscardRelease(string owner, string repository, string name)
202203

203204
if (release is null)
204205
{
205-
throw new Exception(string.Format("Unable to find a release with name {0}", name));
206+
throw new MissingReleaseException(string.Format("Unable to find a release with name {0}", name));
206207
}
207208

208209
if (!release.Draft)
209210
{
210-
throw new Exception("Release is not in draft state, so not discarding.");
211+
throw new InvalidStateException("Release is not in draft state, so not discarding.");
211212
}
212213

213214
await _gitHubClient.Repository.Release.Delete(owner, repository, release.Id).ConfigureAwait(false);
@@ -230,7 +231,7 @@ public async Task AddAssets(string owner, string repository, string tagName, ILi
230231
if (!File.Exists(asset))
231232
{
232233
var logMessage = string.Format("Requested asset to be uploaded doesn't exist: {0}", asset);
233-
throw new Exception(logMessage);
234+
throw new FileNotFoundException(logMessage);
234235
}
235236

236237
var assetFileName = Path.GetFileName(asset);

Source/GitReleaseManager/ReleaseNotesBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public async Task<string> BuildReleaseNotes()
5252
if (issues.Count == 0)
5353
{
5454
var logMessage = string.Format("No closed issues have been found for milestone {0}, or all assigned issues are meant to be excluded from release notes, aborting creation of release.", _milestoneTitle);
55-
throw new Exception(logMessage);
55+
throw new InvalidOperationException(logMessage);
5656
}
5757

5858
if (issues.Count > 0)

0 commit comments

Comments
 (0)