libgit2sharp icon indicating copy to clipboard operation
libgit2sharp copied to clipboard

LibGit2SharpException loses information in HandleError

Open asinghmodesttree opened this issue 1 year ago • 2 comments

In Ensure.HandleError function, since we do not have an exception for handling network errors, when fetch fails and the exception of type LibGit2SharpException exception is thrown, its thrown with arguments (Message, GitErrorCategory) but the exception doesn't have constructor that take an argument of type GitErrorCategory and the closest match is object params which is to handle string format arguments for messages, so the GitErrorCategory information is lost.

File: Ensure.cs:151 new LibGit2SharpException(m, c)

I am trying to understand if there is any technical reason it is done this way?

asinghmodesttree avatar Jun 25 '25 18:06 asinghmodesttree

I didn't realize that GitErrorCategory is internal, closing this.

asinghmodesttree avatar Jun 26 '25 13:06 asinghmodesttree

Hi @asinghmodesttree . This issue has bitten us in the past when the returned error string has curly braces around text. It seems fairly unlikely that the error message would have the {0} value required to be replaced with the GitErrorCategory code.

As a result we have had to put a fix for this in our fork.

Much appreciated if you could merge this PR to avoid this divergence.

zentron avatar Jul 19 '25 06:07 zentron