8000 Handle exceptions and null returns from CredentialsProvider. by chescock · Pull Request #1239 · libgit2/libgit2sharp · GitHub
[go: up one dir, main page]

Skip to content

Handle exceptions and null returns from CredentialsProvider. #1239

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

Closed

Conversation

chescock
Copy link
Contributor
@chescock chescock commented Dec 1, 2015

Add exception handling and null checking around the call to the CredentialsProvider callback and GitCredentialHandler method. Without these, exceptions will cross the boundary into C code, which I believe is bad.

I got here because I want to supply a CredentialsProvider that only applies to certain hosts, and this provides a way to return an error code to libgit2 when I have no credentials to provide.

Pull request #1130 would add a null check here, but not other exception handling. It would translate null to GitErrorCode.Error, while I'm proposing to translate it to GitErrorCode.PassThrough so that a null credentials object behaves like a null credentials provider.

@nulltoken
Copy link
Member

You proposal makes sense to me, but I'd like to get the feedback from other contributors on this.

@whoisj @jamill @ethomson Thoughts?

@whoisj
Copy link
whoisj commented Dec 1, 2015

👍 yes this is a good change. Thanks @chescock .

try
{
var cred = CredentialsProvider(url, username, types);
if (cred == null)
Copy link
Member

Choose a reason for hiding this comment

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

Now that we get rid of a potential NullReferenceException, what would be the behavior from the user perspective of trying to fetch a (private) repository without passing a CredentialsProvider?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A LibGit2SharpException exception will be thrown.

When using WinHTTP, passing null for CredentialsProvider currently throws an exception with the message "Request failed with status code: 401". With this change and libgit2/libgit2#3528 together, passing a CredentialsProvider that returns a null Credentials will have the same message. With just this change, it will instead have the message "No error message has been provided by the native library". I think the other transports will have the message "authentication required but no callback set" in all of those cases.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for your answer. Considering the less than helpful message (from a user perspective), I'd rather wait for the libgit2 PR to be merged before merging this in.

/cc @carlosmn

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nulltoken I think the libgit2 changes were pulled in with #1264, so this will now give friendly messages in all cases.

@whoisj
Copy link
whoisj commented Mar 4, 2016

@carlosmn with @nulltoken on sabbatical, any chance you can take a look at this?

I'm happy with it.

@carlosmn
Copy link
Member
carlosmn commented Mar 7, 2016

Merged manually into master.

@carlosmn carlosmn closed this Mar 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4293
Development

Successfully merging this pull request may close these issues.

4 participants
0