Skip to content
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

GithubClient.Repository.GetAllLanguages throws Exception when the repo does not have a language #1820

Closed
baonguyen96 opened this issue Jun 19, 2018 · 4 comments · Fixed by #1831

Comments

@baonguyen96
Copy link

Example with this API endpoint: https://api.github.com/users/vinhhoa1/repos
Using the above code will crash with this error for repository RPG-ZombiesTCC:

System.ArgumentNullException: Value cannot be null.

Parameter name: source

   at System.Linq.Enumerable.Select[TSource,TResult](IEnumerable`1 source, Func`2 selector)

   at Octokit.RepositoriesClient.<GetAllLanguages>d__84.MoveNext()

I think it would be better if null value are marked as "" (empty) rather than throwing an exception here.

@ryangribble
Copy link
Contributor

Hi @baonguyen96

Can you provide the c# code that produced the error?

The API link you provided (getting all repos for a user) doesn't correlate to the the stack trace. RepositoriesClient.GetAllLanguages() would correspond to https://api.github.com/repos/vinhhoa1/RPG-ZombiesTCC/languages

We definitely dont want an exception like this occurring, but I just want to get the repro code in this issue for completeness 👍

@baonguyen96
Copy link
Author

@ryangribble Sure here is the link to the source code: https://github.com/baonguyen96/GitData/blob/dev/GitData/Storage/Repository.cs

Particularly, it breaks on line 41 (language = await ....) when I call the API to retrieve all languages and any of the language is null:

IReadOnlyList<Octokit.RepositoryLanguage> languages = null;
Task.Run(async () =>
{
                languages = await githubClient.Repository.GetAllLanguages(octokitRepository.Owner.Login, Name);
}).GetAwaiter().GetResult();

This exception does not happen when a repository has at least 1 language.

@ryangribble
Copy link
Contributor

@baonguyen96 can you please take a look at #1831 and let me know if that would suit your needs? Do you have a preference between returning an empty list or returning a null? I went with empty list

@baonguyen96
Copy link
Author

@ryangribble yes I definitely prefer the empty list to null. Thank you.

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 a pull request may close this issue.

2 participants