8000 Add string format ctor to all exceptions and change existing usages · chescock/libgit2sharp@0625b7f · GitHub
[go: up one dir, main page]

Skip to content

Commit 0625b7f

Browse files
Oded WelgreenOded Welgreen
authored andcommitted
Add string format ctor to all exceptions and change existing usages
1 parent 7dd95b8 commit 0625b7f

21 files changed

+158
-33
lines changed

LibGit2Sharp/BareRepositoryException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ public BareRepositoryException(string message)
2525
: base(message)
2626
{ }
2727

28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="LibGit2Sharp.BareRepositoryException"/> class with a specified error message.
30+
/// </summary>
31+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
32+
/// <param name="args">An object array that contains zero or more objects to format.</param>
33+
public BareRepositoryException(string format, params object[] args)
34+
: base(format, args)
35+
{ }
36+
2837
/// <summary>
2938
/// Initializes a new instance of the <see cref="LibGit2Sharp.BareRepositoryException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
3039
/// </summary>

LibGit2Sharp/CheckoutConflictException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line number 9E88 Diff line change
@@ -26,6 +26,15 @@ public CheckoutConflictException(string message)
2626
: base(message)
2727
{ }
2828

29+
/// <summary>
30+
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class with a specified error message.
31+
/// </summary>
32+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
33+
/// <param name="args">An object array that contains zero or more objects to format.</param>
34+
public CheckoutConflictException(string format, params object[] args)
35+
: base(format, args)
36+
{ }
37+
2938
/// <summary>
3039
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
3140
/// </summary>

LibGit2Sharp/Core/Ensure.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,16 +261,14 @@ public static void GitObjectIsNotNull(GitObject gitObject, string identifier)
261261
return;
262262
}
263263

264-
var message = string.Format(CultureInfo.InvariantCulture,
265-
"No valid git object identified by '{0}' exists in the repository.",
266-
identifier);
267-
264+
var messageFormat = "No valid git object identified by '{0}' exists in the repository.";
265+
268266
if (string.Equals("HEAD", identifier, StringComparison.Ordinal))
269267
{
270-
throw new UnbornBranchException(message);
268+
throw new UnbornBranchException(messageFormat, identifier);
271269
}
272270

273-
throw new NotFoundException(message);
271+
throw new NotFoundException(messageFormat, identifier);
274272
}
275273
}
276274
}

LibGit2Sharp/Core/Proxy.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,7 @@ public static void git_filter_register(string name, IntPtr filterPtr, int priori
823823
int res = NativeMethods.git_filter_register(name, filterPtr, priority);
824824
if (res == (int)GitErrorCode.Exists)
825825
{
826-
var message = String.Format("A filter with the name '{0}' is already registered", name);
827-
throw new EntryExistsException(message);
826+
throw new EntryExistsException("A filter with the name '{0}' is already registered", name);
828827
}
829828
Ensure.ZeroResult(res);
830829
}
@@ -2256,7 +2255,7 @@ public static void git_remote_rename(RepositorySafeHandle repo, string name, str
22562255

22572256
if (res == (int)GitErrorCode.NotFound)
22582257
{
2259-
throw new NotFoundException(string.Format("Remote '{0}' does not exist and cannot be renamed.", name));
2258+
throw new NotFoundException("Remote '{0}' does not exist and cannot be renamed.", name);
22602259
}
22612260

22622261
Ensure.ZeroResult(res);
@@ -2404,9 +2403,8 @@ public static RepositorySafeHandle git_repository_open(string path)
24042403

24052404
if (res == (int)GitErrorCode.NotFound)
24062405
{
2407-
throw new RepositoryNotFoundException(String.Format(CultureInfo.InvariantCulture,
2408-
"Path '{0}' doesn't point at a valid Git repository or workdir.",
2409-
path));
2406+
throw new RepositoryNotFoundException("Path '{0}' doesn't point at a valid Git repository or workdir.",
2407+
path);
24102408
}
24112409

24122410
Ensure.ZeroResult(res);
@@ -2435,9 +2433,8 @@ public static void git_repository_open_ext(string path, RepositoryOpenFlags flag
24352433

24362434
if (res == (int)GitErrorCode.NotFound)
24372435
{
2438-
throw new RepositoryNotFoundException(String.Format(CultureInfo.InvariantCulture,
2439-
"Path '{0}' doesn't point at a valid Git repository or workdir.",
2440-
path));
2436+
throw new RepositoryNotFoundException("Path '{0}' doesn't point at a valid Git repository or workdir.",
2437+
path);
24412438
}
24422439

24432440
Ensure.ZeroResult(res);
@@ -3076,8 +3073,8 @@ public static void git_transport_register(String prefix, IntPtr transport_cb, In
30763073

30773074
if (res == (int)GitErrorCode.Exists)
30783075
{
3079-
throw new EntryExistsException(String.Format("A custom transport for '{0}' is already registered",
3080-
prefix));
3076+
throw new EntryExistsException("A custom transport for '{0}' is already registered",
3077+
prefix);
30813078
}
30823079

30833080
Ensure.ZeroResult(res);

LibGit2Sharp/EmptyCommitException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ public EmptyCommitException(string message)
2424
: base(message)
2525
{ }
2626

27+
/// <summary>
28+
/// Initializes a new instance 558 of the <see cref="EmptyCommitException"/> class with a specified error message.
29+
/// </summary>
30+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
31+
/// <param name="args">An object array that contains zero or more objects to format.</param>
32+
public EmptyCommitException(string format, params object[] args)
33+
: base(format, args)
34+
{ }
35+
2736
/// <summary>
2837
/// Initializes a new instance of the <see cref="EmptyCommitException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
2938
/// </summary>

LibGit2Sharp/EntryExistsException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ public EntryExistsException(string message)
2424
: base(message)
2525
{ }
2626

27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="LibGit2Sharp.EntryExistsException"/> class with a specified error message.
29+
/// </summary>
30+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
31+
/// <param name="args">An object array that contains zero or more objects to format.</param>
32+
public EntryExistsException(string format, params object[] args)
33+
: base(format, args)
34+
{ }
35+
2736
/// <summary>
2837
/// Initializes a new instance of the <see cref="LibGit2Sharp.EntryExistsException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
2938
/// </summary>

LibGit2Sharp/InvalidSpecificationException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ public InvalidSpecificationException(string message)
2727
: base(message)
2828
{ }
2929

30+
/// <summary>
31+
/// Initializes a new instance of the <see cref="InvalidSpecificationException"/> class with a specified error message.
32+
/// </summary>
33+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
34+
/// <param name="args">An object array that contains zero or more objects to format.</param>
35+
public InvalidSpecificationException(string format, params object[] args)
36+
: base(format, args)
37+
{ }
38+
3039
/// <summary>
3140
/// Initializes a new instance of the <see cref="InvalidSpecificationException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
3241
/// </summary>

LibGit2Sharp/LockedFileException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ public LockedFileException(string message)
2424
: base(message)
2525
{ }
2626

27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="LibGit2Sharp.LockedFileException"/> class with a specified error message.
29+
/// </summary>
30+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
31+
/// <param name="args">An object array that contains zero or more objects to format.</param>
32+
public LockedFileException(string format, params object[] args)
33+
: base(format, args)
34+
{ }
35+
2736
/// <summary>
2837
/// Initializes a new instance of the <see cref="LibGit2Sharp.LockedFileException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
2938
/// </summary>

LibGit2Sharp/MergeFetchHeadNotFoundException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ public MergeFetchHeadNotFoundException(string message)
2323
: base(message)
2424
{ }
2525

26+
/// <summary>
27+
/// Initializes a new instance of the <see cref="MergeFetchHeadNotFoundException"/> class with a specified error message.
28+
/// </summary>
29+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
30+
/// <param name="args">An object array that contains zero or more objects to format.</param>
31+
public MergeFetchHeadNotFoundException(string format, params object[] args)
32+
: base(format, args)
33+
{ }
34+
2635
/// <summary>
2736
/// Initializes a new instance of the <see cref="MergeFetchHeadNotFoundException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
2837
/// </summary>

LibGit2Sharp/NameConflictException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ public NameConflictException(string message)
2424
: base(message)
2525
{ }
2626

27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="NameConflictException"/> class with a specified error message.
29+
/// </summary>
30+
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
31+
/// <param name="args">An object array that contains zero or more objects to format.</param>
32+
public NameConflictException(string format, params object[] args)
33+
: base(format, args)
34+
{ }
35+
2736
/// <summary>
2837
/// Initializes a new instance of the <see cref="NameConflictException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
2938
/// </summary>

0 commit comments

Comments
 (0)
0