Skip to content

Commit 1d53378

Browse files
author
Dylan Lerch
committed
Do not use string formatting LibGit2SharpException constructor when building unknown exception types
The exception constructors in GitErrorsToLibGit2SharpExceptions make use of the error category by passing it through to the NativeException(string message, GitErrorCategory category) constructor which adds ("libgit2.category", category) to Data on System.Exception. We were calling new LibGit2SharpException(m, c), but this was resolving to the string formatting constructor on LibGit2SharpException, because it does not have a constructor that takes a category. This runs a string format, so if the errorMessage contained any curly braces, that constructor would throw an System.FormatException. This has been changed to just use the message constructor (with no format arguments), and will drop the error code (which is always Unknown anyway).
1 parent 7f48218 commit 1d53378

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

LibGit2Sharp/Core/Ensure.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private static unsafe void HandleError(int result)
148148
Func<string, GitErrorCategory, LibGit2SharpException> exceptionBuilder;
149149
if (!GitErrorsToLibGit2SharpExceptions.TryGetValue((GitErrorCode)result, out exceptionBuilder))
150150
{
151-
exceptionBuilder = (m, c) => new LibGit2SharpException(m, c);
151+
exceptionBuilder = (m, c) => new LibGit2SharpException(m);
152152
}
153153

154154
throw exceptionBuilder(errorMessage, errorCategory);
@@ -256,7 +256,7 @@ public static void GitObjectIsNotNull(GitObject gitObject, string identifier)
256256
}
257257

258258
var messageFormat = "No valid git object identified by '{0}' exists in the repository.";
259-
259+
260260
if (string.Equals("HEAD", identifier, StringComparison.Ordinal))
261261
{
262262
throw new UnbornBranchException(messageFormat, identifier);

0 commit comments

Comments
 (0)