Skip to content

Do not use string formatting LibGit2SharpException constructor - #10

Merged
dylanlerch merged 1 commit into
octopus/masterfrom
dylan/fix-exception-format-error
Nov 2, 2022
Merged

Do not use string formatting LibGit2SharpException constructor#10
dylanlerch merged 1 commit into
octopus/masterfrom
dylan/fix-exception-format-error

Conversation

@dylanlerch

@dylanlerchdylanlerch commented Nov 1, 2022

Copy link
Copy Markdown

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 teamNovember 1, 2022 23:28
@dylanlerch
dylanlerchforce-pushed the dylan/fix-exception-format-error branch from 21ad1af to 1d53378CompareNovember 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
dylanlerchforce-pushed the dylan/fix-exception-format-error branch from 1d53378 to 16435c2CompareNovember 1, 2022 23:32

@acodringtonacodrington left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sneaky overloads hey!
:shipit:

Sign up for freeto 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

@dylanlerch@acodrington