Skip to content

Commit 9f334aa

Browse files
committed
Merge pull request #1202 from odedw/string_format_ctor_for_exceptions
String format ctor for exceptions
2 parents ac4c7d9 + 0625b7f commit 9f334aa

34 files changed

+189
-89
lines changed

LibGit2Sharp/AmbiguousSpecificationException.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ public AmbiguousSpecificationException(string message)
2727
/// <summary>
2828
/// Initializes a new instance of the <see cref="AmbiguousSpecificationException"/> class with a specified error message.
2929
/// </summary>
30-
/// <param name="cultureInfo">An object that supplies culture-specific formatting information.</param>
3130
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
3231
/// <param name="args">An object array that contains zero or more objects to format.</param>
33-
public AmbiguousSpecificationException(CultureInfo cultureInfo, string format, params object[] args)
34-
: base(String.Format(cultureInfo, format, args))
32+
public AmbiguousSpecificationException(string format, params object[] args)
33+
: base(String.Format(format, args))
3534
{
3635
}
3736

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/BranchCollection.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ public virtual Branch Rename(Branch branch, string newName, bool allowOverwrite)
263263

264264
if (branch.IsRemote)
265265
{
266-
throw new LibGit2SharpException(CultureInfo.InvariantCulture,
267-
"Cannot rename branch '{0}'. It's a remote tracking branch.",
266+
throw new LibGit2SharpException("Cannot rename branch '{0}'. It's a remote tracking branch.",
268267
branch.FriendlyName);
269268
}
270269

LibGit2Sharp/CheckoutConflictException.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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/Configuration.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,7 @@ private ConfigurationSafeHandle RetrieveConfigurationHandle(ConfigurationLevel l
693693

694694
if (handle == null && throwIfStoreHasNotBeenFound)
695695
{
696-
throw new LibGit2SharpException(CultureInfo.InvariantCulture,
697-
"No {0} configuration file has been found.",
696+
throw new LibGit2SharpException("No {0} configuration file has been found.",
698697
Enum.GetName(typeof(ConfigurationLevel), level));
699698
}
700699

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: 12 additions & 18 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
}
@@ -1432,9 +1431,8 @@ public static IntPtr git_odb_backend_malloc(IntPtr backend, UIntPtr len)
14321431

14331432
if (IntPtr.Zero == toReturn)
14341433
{
1435-
throw new LibGit2SharpException(CultureInfo.InvariantCulture,
1436-
"Unable to allocate {0} bytes; out of memory",
1437-
len,
1434+
throw new LibGit2SharpException("Unable to allocate {0} bytes; out of memory",
1435+
len,
14381436
GitErrorCode.Error,
14391437
GitErrorCategory.NoMemory);
14401438
}
@@ -2257,7 +2255,7 @@ public static void git_remote_rename(RepositorySafeHandle repo, string name, str
22572255

22582256
if (res == (int)GitErrorCode.NotFound)
22592257
{
2260-
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);
22612259
}
22622260

22632261
Ensure.ZeroResult(res);
@@ -2405,9 +2403,8 @@ public static RepositorySafeHandle git_repository_open(string path)
24052403

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

24132410
Ensure.ZeroResult(res);
@@ -2436,9 +2433,8 @@ public static void git_repository_open_ext(string path, RepositoryOpenFlags flag
24362433

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

24442440
Ensure.ZeroResult(res);
@@ -2556,8 +2552,7 @@ public static Tuple<GitObjectSafeHandle, ReferenceSafeHandle> git_revparse_ext(R
25562552
return null;
25572553

25582554
case (int)GitErrorCode.Ambiguous:
2559-
throw new AmbiguousSpecificationException(CultureInfo.InvariantCulture,
2560-
"Provided abbreviated ObjectId '{0}' is too short.",
2555+
throw new AmbiguousSpecificationException("Provided abbreviated ObjectId '{0}' is too short.",
25612556
objectish);
25622557

25632558
default:
@@ -2778,8 +2773,7 @@ public static FileStatus git_status_file(RepositorySafeHandle repo, FilePath pat
27782773
return FileStatus.Nonexistent;
27792774

27802775
case (int)GitErrorCode.Ambiguous:
2781-
throw new AmbiguousSpecificationException(CultureInfo.InvariantCulture,
2782-
"More than one file matches the pathspec '{0}'. " +
2776+
throw new AmbiguousSpecificationException("More than one file matches the pathspec '{0}'. " +
27832777
"You can either force a literal path evaluation " +
27842778
"(GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH), or use git_status_foreach().",
27852779
path);
@@ -3079,8 +3073,8 @@ public static void git_transport_register(String prefix, IntPtr transport_cb, In
30793073

30803074
if (res == (int)GitErrorCode.Exists)
30813075
{
3082-
throw new EntryExistsException(String.Format("A custom transport for '{0}' is already registered",
3083-
prefix));
3076+
throw new EntryExistsException("A custom transport for '{0}' is already registered",
3077+
prefix);
30843078
}
30853079

30863080
Ensure.ZeroResult(res);

LibGit2Sharp/Diff.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ private static T BuildDiffResult<T>(DiffSafeHandle diff) where T : class, IDiffR
109109

110110
if (!ChangesBuilders.TryGetValue(typeof(T), out builder))
111111
{
112-
throw new LibGit2SharpException(CultureInfo.InvariantCulture,
113-
"User-defined types passed to Compare are not supported. Supported values are: {0}",
112+
throw new LibGit2SharpException("User-defined types passed to Compare are not supported. Supported values are: {0}",
114113
string.Join(", ", ChangesBuilders.Keys.Select(x => x.Name)));
115114
}
116115

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 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/GitObject.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ internal static GitObject BuildFrom(Repository repo, ObjectId id, GitObjectType
7777
return new Blob(repo, id);
7878

7979
default:
80-
throw new LibGit2SharpException(CultureInfo.InvariantCulture,
81-
"Unexpected type '{0}' for object '{1}'.",
80+
throw new LibGit2SharpException("Unexpected type '{0}' for object '{1}'.",
8281
type,
8382
id);
8483
}

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/LibGit2SharpException.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ public LibGit2SharpException(string message, Exception innerException)
3737
/// <summary>
3838
/// Initializes a new instance of the <see cref="LibGit2SharpException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
3939
/// </summary>
40-
/// <param name="cultureInfo">An object that supplies culture-specific formatting information.</param>
4140
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
4241
/// <param name="args">An object array that contains zero or more objects to format.</param>
43-
public LibGit2SharpException(CultureInfo cultureInfo, string format, params object[] args)
44-
: base(String.Format(cultureInfo, format, args))
42+
public LibGit2SharpException(string format, params object[] args)
43+
: base(String.Format(CultureInfo.InvariantCulture, format, args))
4544
{
4645
}
4746

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>

LibGit2Sharp/Network.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,7 @@ public virtual void Push(
399399
{
400400
if (string.IsNullOrEmpty(branch.UpstreamBranchCanonicalName))
401401
{
402-
throw new LibGit2SharpException(
403-
CultureInfo.InvariantCulture,
404-
"The branch '{0}' (\"{1}\") that you are trying to push does not track an upstream branch.",
402+
throw new LibGit2SharpException("The branch '{0}' (\"{1}\") that you are trying to push does not track an upstream branch.",
405403
branch.FriendlyName, branch.CanonicalName);
406404
}
407405
}

LibGit2Sharp/NonFastForwardException.cs

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

28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="LibGit2Sharp.NonFastForwardException"/> 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 NonFastForwardException(string format, params object[] args)
34+
: base(format, args)
35+
{ }
36+
2837
/// <summary>
2938
/// Initializes a new instance of the <see cref="LibGit2Sharp.NonFastForwardException"/> class with a specified error message and a reference to the inner exception that is the cause of this exception.
3039
/// </summary>

LibGit2Sharp/NotFoundException.cs

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

27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="LibGit2Sharp.NotFoundException"/> 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 NotFoundException(string format, params object[] args)
33+
: base(format, args)
34+
{ }
35+
2736
/// <summary>
2837
/// Initializes a new instance of the <see cref="LibGit2Sharp.NotFoundException"/> 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)