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

NullReferenceException when API quota is exceeded #239

Open
terrajobst opened this issue Jul 15, 2020 · 4 comments
Open

NullReferenceException when API quota is exceeded #239

terrajobst opened this issue Jul 15, 2020 · 4 comments
Labels
Type: Bug Something isn't working as documented

Comments

@terrajobst
Copy link

terrajobst commented Jul 15, 2020

Update: The issue seems to be independent of the query and occurs when the API rate limit is exceeded.

When executing this query:

            var query = new Query()
                .Organization(orgName)
                .Team(Var("teamSlug"))
                .Repositories(first: 100, after: Var("after"))
                .Select(connection => new
                {
                    connection.PageInfo.EndCursor,
                    connection.PageInfo.HasNextPage,
                    connection.TotalCount,
                    Items = connection.Edges.Select(e => new
                    {
                        e.Node.Name,
                        e.Permission
                    }).ToList(),
                }).Compile();

            var result = new List<CachedTeamAccess>();

            foreach (var teamSlug in teamSlugs)
            {
                var vars = new Dictionary<string, object>
                {
                    { "after", null },
                    { "teamSlug", teamSlug },
                };

                var current = await Connection.Run(query, vars);
                vars["after"] = current.HasNextPage ? current.EndCursor : null;

                while (vars["after"] != null)
                {
                    var page = await Connection.Run(query, vars);
                    current.Items.AddRange(page.Items);
                    vars["after"] = page.HasNextPage
                                        ? page.EndCursor
                                        : null;
                }

I sometimes get the following exceptions:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at Octokit.GraphQL.Core.Deserializers.ResponseDeserializer.DeserializeException(JToken error)
   at Octokit.GraphQL.Core.Deserializers.ResponseDeserializer.Deserialize[TResult](Func`2 deserialize, JObject data)
   at Octokit.GraphQL.Core.SimpleQuery`1.Runner.<RunPage>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Octokit.GraphQL.ConnectionExtensions.<Run>d__2`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.DotnetOrg.GitHubCaching.CacheLoader.<GetCachedTeamAccessAsync>d__15.MoveNext() in D:\a\1\s\src\Microsoft.DotnetOrg.GitHubCaching\CacheLoader.cs:line 260
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at Octokit.GraphQL.Core.Deserializers.ResponseDeserializer.DeserializeException(JToken error)
   at Octokit.GraphQL.Core.Deserializers.ResponseDeserializer.Deserialize[TResult](Func`2 deserialize, JObject data)
   at Octokit.GraphQL.Core.SimpleQuery`1.Runner.<RunPage>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Octokit.GraphQL.ConnectionExtensions.<Run>d__2`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.DotnetOrg.GitHubCaching.CacheLoader.<GetCachedMembersAsync>d__16.MoveNext() in D:\a\1\s\src\Microsoft.DotnetOrg.GitHubCaching\CacheLoader.cs:line 309
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.DotnetOrg.GitHubCaching.CacheLoader.<LoadAsync>d__10.MoveNext() in D:\a\1\s\src\Microsoft.DotnetOrg.GitHubCaching\CacheLoader.cs:line 43
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.DotnetOrg.PolicyCop.Commands.CacheOrgCommand.<ExecuteAsync>d__7.MoveNext() in D:\a\1\s\src\policop\Commands\CacheOrgCommand.cs:line 38
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.DotnetOrg.PolicyCop.Program.<Main>d__0.MoveNext() in D:\a\1\s\src\policop\Program.cs:line 73
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.DotnetOrg.PolicyCop.Program.<Main>(String[] args)

Any ideas?

@jcansdale
Copy link
Collaborator

@terrajobst,

Any idea which element is coming up null? You could try adding some guards like this:

Items = connection.Edges.Select(e => new
                    {
                        Name = e.Node != null ? e.Node.Name : null,
                        e.Permission
                    }).ToList(),

I don't think we can use e.Node?.Name because it's an expression.

@terrajobst
Copy link
Author

No, I've got zero idea and it very much nether repros locally :(

But by looking at the stack trace I'm inclined to say that bug isn't the schema but somewhere in your deserializer...

@terrajobst terrajobst changed the title NullReferenceException NullReferenceException when API quota is exceeded Aug 26, 2020
@terrajobst
Copy link
Author

Update: The issue seems to be independent of the query and occurs when the API rate limit is exceeded.

@github-actions
Copy link

github-actions bot commented Dec 3, 2022

👋 Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!

@github-actions github-actions bot added the Status: Stale Used by stalebot to clean house label Dec 3, 2022
@kfcampbell kfcampbell added Priority: Normal Type: Bug Something isn't working as documented labels Dec 5, 2022
@github-actions github-actions bot removed the Status: Stale Used by stalebot to clean house label Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as documented
Projects
None yet
Development

No branches or pull requests

4 participants