Skip to content

Handle exceptions and null returns from CredentialsProvider.#1239

Closed
chescock wants to merge 1 commit into
libgit2:vNextfrom
chescock:CredentialsProvider-Error-handling
Closed

Handle exceptions and null returns from CredentialsProvider.#1239
chescock wants to merge 1 commit into
libgit2:vNextfrom
chescock:CredentialsProvider-Error-handling

Conversation

@chescock

@chescock chescock commented Dec 1, 2015

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

whoisj commented Dec 1, 2015

Copy link
Copy Markdown

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

whoisj commented Mar 4, 2016

Copy link
Copy Markdown

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

I'm happy with it.

@carlosmn

carlosmn commented Mar 7, 2016

Copy link
Copy Markdown
Member

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

Development

Successfully merging this pull request may close these issues.

4 participants