Skip to content

Commit bdc9c40

Browse files
Dylan Lerchzentron
authored andcommitted
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 8e55046 commit bdc9c40

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

LibGit2Sharp/Core/Ensure.cs

Lines changed: 1 addition & 1 deletion
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);

0 commit comments

Comments
 (0)