libgit2sharp icon indicating copy to clipboard operation
libgit2sharp copied to clipboard

Do not use `LibGit2SharpException` overload for unknown message

Open zentron opened this issue 5 months ago • 1 comments

Background

The LibGit2SharpException class has a constructor overload that takes two parameters and attempts to call String.Format to convert the values into a single string.

Unfortunately if the provided message contains text between curly braces then the string.format throws an exception.

Related PR https://github.com/OctopusDeploy/libgit2sharp/pull/10

Result

Since this message could have any value, it seems risky to assume that the provided string will have a {0} that will accept the GitErrorCategory as a replacement value. In fact it seems rather unlikely that this would typically apply at all. As a result this handler would ignore the error category in the best case, or throw an exception in the worst case.

Alternative

I'd also be happy to ignore the category entirely since its likely that it is of type GitErrorCategory.Unknown anyway

Alternative snippet

exceptionBuilder = (m, c) => new LibGit2SharpException(m);

zentron avatar Jul 19 '25 06:07 zentron

@bording this is related to a closed issue https://github.com/libgit2/libgit2sharp/issues/2159

zentron avatar Jul 19 '25 06:07 zentron