Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Do not use string formatting LibGit2SharpException constructor #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2022

Conversation

dylanlerch
Copy link

@dylanlerch dylanlerch commented Nov 1, 2022

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)

@dylanlerch dylanlerch requested a review from a team November 1, 2022 23:28
@dylanlerch dylanlerch force-pushed the dylan/fix-exception-format-error branch from 21ad1af to 1d53378 Compare November 1, 2022 23:31
…uilding 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).
@dylanlerch dylanlerch force-pushed the dylan/fix-exception-format-error branch from 1d53378 to 16435c2 Compare November 1, 2022 23:32
Copy link

@acodrington acodrington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sneaky overloads hey!
:shipit:

@dylanlerch dylanlerch merged commit 6da159a into octopus/master Nov 2, 2022
@dylanlerch dylanlerch deleted the dylan/fix-exception-format-error branch November 2, 2022 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants