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

[fix]: Add missing "waiting" enum to WorkflowJobStatus.cs #364

Merged
merged 3 commits into from
Oct 12, 2023
Merged

[fix]: Add missing "waiting" enum to WorkflowJobStatus.cs #364

merged 3 commits into from
Oct 12, 2023

Conversation

rasmus
Copy link
Contributor

@rasmus rasmus commented Oct 9, 2023

The WorkflowJobStatus enum is lacking the Waiting, which cases an exception.

[Parameter(Value = "waiting")]
Waiting,
System.AggregateException: An error occurred while writing to logger(s). (Value 'waiting' is not a valid 'WorkflowJobStatus' enum value.)  ---> System.ArgumentException: Value 'waiting' is not a valid 'WorkflowJobStatus' enum value.   
   at Octokit.Webhooks.Extensions.StringEnum`1.ParseValue()   
   at Octokit.Webhooks.Extensions.StringEnum`1.get_Value()   
   at Octokit.Webhooks.Extensions.StringEnum`1.PrintMembers(StringBuilder builder)   
   at Octokit.Webhooks.Extensions.StringEnum`1.ToString()   
   at Octokit.Webhooks.Models.WorkflowJobEvent.WorkflowJob.PrintMembers(StringBuilder builder)   
   at Octokit.Webhooks.Models.WorkflowJobEvent.WorkflowJob.ToString()   
   at Octokit.Webhooks.Events.WorkflowJobEvent.PrintMembers(StringBuilder builder)   
   at Octokit.Webhooks.Events.WorkflowJob.WorkflowJobWaitingEvent.PrintMembers(StringBuilder builder)   
   at Octokit.Webhooks.Events.WorkflowJob.WorkflowJobWaitingEvent.ToString()   
   at Microsoft.Extensions.Logging.Console.JsonConsoleFormatter.WriteItem(Utf8JsonWriter writer, KeyValuePair`2 item)   
   at Microsoft.Extensions.Logging.Console.JsonConsoleFormatter.<WriteScopeInformation>b__4_0(Object scope, Utf8JsonWriter state)   
   at Microsoft.Extensions.Logging.LoggerFactoryScopeProvider.ForEachScope[TState](Action`2 callback, TState state)   
   at Microsoft.Extensions.Logging.Console.JsonConsoleFormatter.WriteScopeInformation(Utf8JsonWriter writer, IExternalScopeProvider scopeProvider)   
   at Microsoft.Extensions.Logging.Console.JsonConsoleFormatter.Write[TState](LogEntry`1& logEntry, IExternalScopeProvider scopeProvider, TextWriter textWriter)   
   at Microsoft.Extensions.Logging.Console.ConsoleLogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)   
   at Microsoft.Extensions.Logging.Logger.<Log>g__LoggerLog|12_0[TState](LogLevel logLevel, EventId eventId, ILogger logger, Exception exception, Func`3 formatter, List`1& exceptions, TState& state)    
   --- End of inner exception stack trace ---   
   at Microsoft.Extensions.Logging.Logger.ThrowLoggingError(List`1 exceptions)   
   at Microsoft.Extensions.Logging.Logger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)   
   at Microsoft.Extensions.Logging.Logger`1.Microsoft.Extensions.Logging.ILogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)   
   at Microsoft.Extensionsging.LoggerExtensions.Log.Log(ILogger logger, LogLevel logLevel, EventId eventId, Exception exception, String message, Object[] args)   
 [...]

Before the change?

  • Exception being thrown due to unknown enum value

After the change?

  • No exception

Pull request checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

JamieMagee
JamieMagee previously approved these changes Oct 9, 2023
@JamieMagee
Copy link
Contributor

Thanks for the contribution!

Can I ask what was the cause of the exception? StringEnum was supposed to prevent this type of exception.

I'm limited in the amount of debugging I can do right now as I'm traveling the next couple of days and only have mobile access.

@rasmus
Copy link
Contributor Author

rasmus commented Oct 9, 2023

Just had a (very quick) read through the StringEnum and it seems to throw an exception if the value isn't define

@nickfloyd nickfloyd changed the title Add missing "waiting" enum to WorkflowJobStatus.cs [fix]: Add missing "waiting" enum to WorkflowJobStatus.cs Oct 10, 2023
@nickfloyd nickfloyd added the Type: Bug Something isn't working as documented label Oct 10, 2023
@nickfloyd
Copy link
Collaborator

Hey @rasmus,

For clarity the file you were looking to changed is WorkflowJobStatus

According to the schema status' for workflow jobs are limited to:

"status": {
  "description": "The phase of the lifecycle that the job is currently in.",
  "type": "string",
  "enum": [
    "queued",
    "in_progress",
    "completed"
  ],
  "examples": [
    "queued"
 ]
},

Workflow runs on the other hand have a much more broad set of status' - they can be viewed in the docs here.

I can totally see where this can be confusing so I wanted to clarity which one (Workflow Jobs or Workflow Runs) were you wanting to work with?

@rasmus
Copy link
Contributor Author

rasmus commented Oct 11, 2023

I admit, this PR was created while we were doing a hectic debug session on our own bug and this popped up in the logs.

The initial commit was a copy-paste from the WorkflowJobStatus, so I thought it was a mistake in this project as its in the other and we saw the exception in our logs.
https://github.com/octokit/octokit.net/blob/main/Octokit/Models/Response/WorkflowJobStatus.cs#L13-L14

@rasmus
Copy link
Contributor Author

rasmus commented Oct 11, 2023

Captured a event in the wild with the waiting value in the event. Tried to remove any critical data from the payload.

Sent from GitHub Enterprise Version 3.8.1

{
  "action": "waiting",
  "workflow_job": {
    "id": 5775885,
    "run_id": 783732,
    "run_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/actions/runs/783732",
    "run_attempt": 1,
    "node_id": "MDg6Q2hlY2tSdW41Nzc1ODg1",
    "head_sha": "39d9c4327ce3632032af0751596204fd1187ed5a",
    "url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/actions/jobs/5775885",
    "html_url": "https://github.dummy-hostname.org/some-org/some-repo/actions/runs/783732/jobs/1402302",
    "status": "waiting",
    "conclusion": null,
    "started_at": "2023-10-11T07:02:47Z",
    "completed_at": null,
    "name": "some name of deploy",
    "steps": [

    ],
    "check_run_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/check-runs/5775885",
    "labels": [
      "self-hosted",
      "ubuntu-latest"
    ],
    "runner_id": null,
    "runner_name": null,
    "runner_group_id": null,
    "runner_group_name": null
  },
  "deployment": {
    "url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/deployments/92176",
    "id": 92176,
    "node_id": "MDEwOkRlcGxveW1lbnQ5MjE3Ng==",
    "task": "deploy",
    "original_environment": "some env",
    "environment": "some env",
    "description": null,
    "created_at": "2023-10-11T07:02:47Z",
    "updated_at": "2023-10-11T07:02:47Z",
    "statuses_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/deployments/92176/statuses",
    "repository_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo",
    "creator": {
      "login": "some-name",
      "id": 1555,
      "node_id": "MDQ6VXNlcjE1NTU=",
      "avatar_url": "https://avatars.github.dummy-hostname.org/u/1555?",
      "gravatar_id": "",
      "url": "https://github.dummy-hostname.org/api/v3/users/some-name",
      "html_url": "https://github.dummy-hostname.org/some-name",
      "followers_url": "https://github.dummy-hostname.org/api/v3/users/some-name/followers",
      "following_url": "https://github.dummy-hostname.org/api/v3/users/some-name/following{/other_user}",
      "gists_url": "https://github.dummy-hostname.org/api/v3/users/some-name/gists{/gist_id}",
      "starred_url": "https://github.dummy-hostname.org/api/v3/users/some-name/starred{/owner}{/repo}",
      "subscriptions_url": "https://github.dummy-hostname.org/api/v3/users/some-name/subscriptions",
      "organizations_url": "https://github.dummy-hostname.org/api/v3/users/some-name/orgs",
      "repos_url": "https://github.dummy-hostname.org/api/v3/users/some-name/repos",
      "events_url": "https://github.dummy-hostname.org/api/v3/users/some-name/events{/privacy}",
      "received_events_url": "https://github.dummy-hostname.org/api/v3/users/some-name/received_events",
      "type": "User",
      "site_admin": false
    },
    "sha": "39d9c4327ce3632032af0751596204fd1187ed5a",
    "ref": "master",
    "payload": {

    },
    "transient_environment": false,
    "production_environment": false,
    "performed_via_github_app": null
  },
  "repository": {
    "id": 37825,
    "node_id": "MDEwOlJlcG9zaXRvcnkzNzgyNQ==",
    "name": "some-repo",
    "full_name": "some-org/some-repo",
    "private": false,
    "owner": {
      "login": "some-org",
      "id": 366,
      "node_id": "MDEyOk9yZ2FuaXphdGlvbjM2Ng==",
      "avatar_url": "https://avatars.github.dummy-hostname.org/u/366?",
      "gravatar_id": "",
      "url": "https://github.dummy-hostname.org/api/v3/users/some-org",
      "html_url": "https://github.dummy-hostname.org/some-org",
      "followers_url": "https://github.dummy-hostname.org/api/v3/users/some-org/followers",
      "following_url": "https://github.dummy-hostname.org/api/v3/users/some-org/following{/other_user}",
      "gists_url": "https://github.dummy-hostname.org/api/v3/users/some-org/gists{/gist_id}",
      "starred_url": "https://github.dummy-hostname.org/api/v3/users/some-org/starred{/owner}{/repo}",
      "subscriptions_url": "https://github.dummy-hostname.org/api/v3/users/some-org/subscriptions",
      "organizations_url": "https://github.dummy-hostname.org/api/v3/users/some-org/orgs",
      "repos_url": "https://github.dummy-hostname.org/api/v3/users/some-org/repos",
      "events_url": "https://github.dummy-hostname.org/api/v3/users/some-org/events{/privacy}",
      "received_events_url": "https://github.dummy-hostname.org/api/v3/users/some-org/received_events",
      "type": "Organization",
      "site_admin": false
    },
    "html_url": "https://github.dummy-hostname.org/some-org/some-repo",
    "description": "some description",
    "fork": false,
    "url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo",
    "forks_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/forks",
    "keys_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/keys{/key_id}",
    "collaborators_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/collaborators{/collaborator}",
    "teams_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/teams",
    "hooks_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/hooks",
    "issue_events_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/issues/events{/number}",
    "events_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/events",
    "assignees_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/assignees{/user}",
    "branches_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/branches{/branch}",
    "tags_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/tags",
    "blobs_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/git/blobs{/sha}",
    "git_tags_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/git/tags{/sha}",
    "git_refs_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/git/refs{/sha}",
    "trees_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/git/trees{/sha}",
    "statuses_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/statuses/{sha}",
    "languages_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/languages",
    "stargazers_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/stargazers",
    "contributors_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/contributors",
    "subscribers_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/subscribers",
    "subscription_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/subscription",
    "commits_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/commits{/sha}",
    "git_commits_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/git/commits{/sha}",
    "comments_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/comments{/number}",
    "issue_comment_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/issues/comments{/number}",
    "contents_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/contents/{+path}",
    "compare_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/compare/{base}...{head}",
    "merges_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/merges",
    "archive_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/{archive_format}{/ref}",
    "downloads_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/downloads",
    "issues_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/issues{/number}",
    "pulls_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/pulls{/number}",
    "milestones_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/milestones{/number}",
    "notifications_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/notifications{?since,all,participating}",
    "labels_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/labels{/name}",
    "releases_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/releases{/id}",
    "deployments_url": "https://github.dummy-hostname.org/api/v3/repos/some-org/some-repo/deployments",
    "created_at": "2020-07-08T11:13:43Z",
    "updated_at": "2022-08-09T13:21:23Z",
    "pushed_at": "2023-10-11T06:55:48Z",
    "git_url": "git://github.dummy-hostname.org/some-org/some-repo.git",
    "ssh_url": "[email protected]:some-org/some-repo.git",
    "clone_url": "https://github.dummy-hostname.org/some-org/some-repo.git",
    "svn_url": "https://github.dummy-hostname.org/some-org/some-repo",
    "homepage": null,
    "size": 7082,
    "stargazers_count": 0,
    "watchers_count": 0,
    "language": "TypeScript",
    "has_issues": false,
    "has_projects": false,
    "has_downloads": true,
    "has_wiki": false,
    "has_pages": false,
    "has_discussions": false,
    "forks_count": 0,
    "mirror_url": null,
    "archived": false,
    "disabled": false,
    "open_issues_count": 6,
    "license": null,
    "allow_forking": true,
    "is_template": false,
    "web_commit_signoff_required": false,
    "topics": [
      "something-else",
      "something"
    ],
    "visibility": "public",
    "forks": 0,
    "open_issues": 6,
    "watchers": 0,
    "default_branch": "master"
  },
  "organization": {
    "login": "some-org",
    "id": 366,
    "node_id": "MDEyOk9yZ2FuaXphdGlvbjM2Ng==",
    "url": "https://github.dummy-hostname.org/api/v3/orgs/some-org",
    "repos_url": "https://github.dummy-hostname.org/api/v3/orgs/some-org/repos",
    "events_url": "https://github.dummy-hostname.org/api/v3/orgs/some-org/events",
    "hooks_url": "https://github.dummy-hostname.org/api/v3/orgs/some-org/hooks",
    "issues_url": "https://github.dummy-hostname.org/api/v3/orgs/some-org/issues",
    "members_url": "https://github.dummy-hostname.org/api/v3/orgs/some-org/members{/member}",
    "public_members_url": "https://github.dummy-hostname.org/api/v3/orgs/some-org/public_members{/member}",
    "avatar_url": "https://avatars.github.dummy-hostname.org/u/366?",
    "description": "Archived repos should be moved to the \"some-org-attic\" organization"
  },
  "enterprise": {
    "id": 1,
    "slug": "enterprise-slug",
    "name": "Enterprise-Name",
    "node_id": "MDEwOkVudGVycHJpc2Ux",
    "avatar_url": "https://avatars.github.dummy-hostname.org/b/1?",
    "description": null,
    "website_url": null,
    "html_url": "https://github.dummy-hostname.org/enterprises/enterprise-slug",
    "created_at": "2019-07-31T19:01:23Z",
    "updated_at": "2022-11-06T21:06:44Z"
  },
  "sender": {
    "login": "some-name",
    "id": 1555,
    "node_id": "MDQ6VXNlcjE1NTU=",
    "avatar_url": "https://avatars.github.dummy-hostname.org/u/1555?",
    "gravatar_id": "",
    "url": "https://github.dummy-hostname.org/api/v3/users/some-name",
    "html_url": "https://github.dummy-hostname.org/some-name",
    "followers_url": "https://github.dummy-hostname.org/api/v3/users/some-name/followers",
    "following_url": "https://github.dummy-hostname.org/api/v3/users/some-name/following{/other_user}",
    "gists_url": "https://github.dummy-hostname.org/api/v3/users/some-name/gists{/gist_id}",
    "starred_url": "https://github.dummy-hostname.org/api/v3/users/some-name/starred{/owner}{/repo}",
    "subscriptions_url": "https://github.dummy-hostname.org/api/v3/users/some-name/subscriptions",
    "organizations_url": "https://github.dummy-hostname.org/api/v3/users/some-name/orgs",
    "repos_url": "https://github.dummy-hostname.org/api/v3/users/some-name/repos",
    "events_url": "https://github.dummy-hostname.org/api/v3/users/some-name/events{/privacy}",
    "received_events_url": "https://github.dummy-hostname.org/api/v3/users/some-name/received_events",
    "type": "User",
    "site_admin": false
  },
  "installation": {
    "id": 1199,
    "node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uMTE5OQ=="
  }
}

image

@nickfloyd
Copy link
Collaborator

@rasmus Got it! Thank you for the clarification! As expected, you are correct. It seems that our documents are incorrect (as well as our OpenAPI schema). Something similar has been reported by other users as well and also fixed in Octokit.net.

Once we get CI green, we'll work to get this in. I'll also be creating a ticket to address the inaccuracy in the OpenAPI definition. Apologies for all of the trouble.

@JamieMagee
Copy link
Contributor

Just had a (very quick) read through the StringEnum and it seems to throw an exception if the value isn't define

You can guard against this by using the TryParse method on StringEnum. See the documentation for more info.

@JamieMagee JamieMagee enabled auto-merge (squash) October 12, 2023 21:14
@JamieMagee JamieMagee requested a review from nickfloyd October 12, 2023 21:14
@JamieMagee JamieMagee merged commit f91473c into octokit:main Oct 12, 2023
7 checks passed
@nickfloyd
Copy link
Collaborator

@rasmus Just a quick follow up. I submitted a PR to get this updated in the GitHub OpenAPI definitions. Hopefully that will get published and into docs once it has been merged.

@rasmus rasmus deleted the patch-1 branch October 13, 2023 06:34
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
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants