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

[BUG]: client.last_response is nil when workflow_dispatch is called on a non-existent workflow #1571

Open
1 task done
itskingori opened this issue May 10, 2023 · 0 comments
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented

Comments

@itskingori
Copy link

itskingori commented May 10, 2023

What happened?

When you call workflow_dispatch with the workflow-id of a non-existent workflow like so ...

begin
  options = { inputs: { environment: 'production' } }
  client = Octokit::Client.new access_token: access_token
  client.workflow_dispatch repository_uid, "deploy-nonexistent.yml", ref, options
  response = client.last_response
  response_status = response.status
rescue Octokit::NotFound, Octokit::UnprocessableEntity => e
  response_body = JSON.parse(e.response_body)
  response_status = e.response_status
end

You'd expect Octokit::NotFound to be raised but instead client.last_response is set to nil. I recorded the HTTP interaction using VCR and it does return a 404 Not Found, it seems the client is the one that's not parsing the response correctly? 😕

---
http_interactions:
  - request:
      method: post
      uri: https://api.github.com/repositories/427663506/actions/workflows/deploy-nonexistent.yml/dispatches
      body:
        encoding: UTF-8
        string: '{"inputs":{"environment":"production"},"ref":"refs/heads/main"}'
      headers:
        Accept:
          - application/vnd.github.v3+json
        User-Agent:
          - Octokit Ruby Gem 6.1.1
        Content-Type:
          - application/json
        Authorization:
          - token <TOKEN>
        Accept-Encoding:
          - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
    response:
      status:
        code: 404
        message: Not Found
      headers:
        Server:
          - GitHub.com
        Date:
          - Tue, 09 May 2023 06:09:34 GMT
        Content-Type:
          - application/json; charset=utf-8
        Transfer-Encoding:
          - chunked
        X-Oauth-Scopes:
          - ""
        X-Accepted-Oauth-Scopes:
          - ""
        X-Oauth-Client-Id:
          - Iv1.1148b5f910aca975
        Github-Authentication-Token-Expiration:
          - 2023-05-09 10:21:38 UTC
        X-Github-Media-Type:
          - github.v3; format=json
        X-Github-Api-Version-Selected:
          - "2022-11-28"
        X-Ratelimit-Limit:
          - "5000"
        X-Ratelimit-Remaining:
          - "4970"
        X-Ratelimit-Reset:
          - "1683613880"
        X-Ratelimit-Used:
          - "30"
        X-Ratelimit-Resource:
          - core
        Access-Control-Expose-Headers:
          - ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining,
            X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes,
            X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO,
            X-GitHub-Request-Id, Deprecation, Sunset
        Access-Control-Allow-Origin:
          - "*"
        Strict-Transport-Security:
          - max-age=31536000; includeSubdomains; preload
        X-Frame-Options:
          - deny
        X-Content-Type-Options:
          - nosniff
        X-Xss-Protection:
          - "0"
        Referrer-Policy:
          - origin-when-cross-origin, strict-origin-when-cross-origin
        Content-Security-Policy:
          - default-src 'none'
        Vary:
          - Accept-Encoding, Accept, X-Requested-With
        X-Github-Request-Id:
          - D3A6:3D9F:207F49:2C58BA:6459E39E
      body:
        encoding: ASCII-8BIT
        string: |-
          {
            "message": "Not Found",
            "documentation_url": "https://docs.github.com/rest/reference/actions#create-a-workflow-dispatch-event"
          }
    recorded_at: Tue, 09 May 2023 06:09:34 GMT
recorded_with: VCR 6.1.0

Obviously I can check for nil and handle it but it does seem to be an awkward design. If it was a 204 No Content maybe nil would make sense? 🤔 Something along the lines of ... it's because this method returns a boolean response and so a nil return is a way of saying there's an error. If return:

  • true - it worked, dispatched!
  • `false - it didn't worked, not dispatched!
  • nil - something went wrong?

The odd thing is that when true, you do get a response in client.last_response. I don't know how to get it to have a false return for me to test what I would get there. Anyway, bug maybe? 🤷🏽‍♂️

Versions

  • Ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
  • Octokit Ruby Gem 6.1.1

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@itskingori itskingori added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels May 10, 2023
@itskingori itskingori changed the title [BUG]: client.last_response is nil when workflow_dispatch is called on a non-existent workflow [BUG]: client.last_response is nil when workflow_dispatch is called on a non-existent workflow May 10, 2023
@kfcampbell kfcampbell added Priority: Normal Status: Up for grabs Issues that are ready to be worked on by anyone and removed Status: Triage This is being looked at and prioritized labels May 15, 2023
@nickfloyd nickfloyd added the hacktoberfest Issues for participation in Hacktoberfest label Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented
Projects
Status: 🔥 Backlog
Development

No branches or pull requests

3 participants