Skip to content

fix(organization_ruleset): handle other error responses#2705

Merged
nickfloyd merged 7 commits intointegrations:mainfrom
skeggse:patch-1
Dec 1, 2025
Merged

fix(organization_ruleset): handle other error responses#2705
nickfloyd merged 7 commits intointegrations:mainfrom
skeggse:patch-1

Conversation

@skeggse
Copy link
Copy Markdown
Contributor

@skeggse skeggse commented Jul 17, 2025

Resolves #2450


Before the change?

If an error occurs that is NOT a github.ErrorResponse or is a github.ErrorResponse with a status code other than 304 or 404 the current implementation will:

Not return from the function and continue executing and try to access resp.Header and ruleset.Name. Since both resp and ruleset are nil when there's an error we get a SIGSEGV

After the change?

  • Valid error response

Pull request checklist

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

Does this introduce a breaking change?

  • Yes
  • No

@nickfloyd nickfloyd moved this from Backlog to In Progress in Terraform Provider Nov 20, 2025
@nickfloyd nickfloyd moved this from In Progress to In Review in Terraform Provider Nov 20, 2025
@nickfloyd nickfloyd added this to the v6.x version wrap up milestone Nov 20, 2025
@diofeher diofeher self-requested a review November 23, 2025 03:07
Copy link
Copy Markdown
Collaborator

@diofeher diofeher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skeggse Could you please add more context to the pull request's description about how you've fixed the problem and include an automated test demonstrating how this new functionality is expected to resolve the issue linked on the PR?

@github-project-automation github-project-automation bot moved this from 🆕 Triage to 🏗 In progress in 🧰 Octokit Active Nov 23, 2025
@diofeher diofeher self-assigned this Nov 23, 2025
@nickfloyd
Copy link
Copy Markdown
Member

@diofeher Due to the length of time it has taken to get this in, I'll step in and complete the PR description. After running some local tests this is what I came up with:

If an error occurs that is NOT a github.ErrorResponse or is a github.ErrorResponse with a status code other than 304 or 404 the current implementation will:

Not return from the function and continue executing and try to access resp.Header and ruleset.Name. Since both resp and ruleset are nil when there's an error we get a SIGSEGV

@nickfloyd nickfloyd requested a review from diofeher November 26, 2025 20:57
@deiga
Copy link
Copy Markdown
Collaborator

deiga commented Nov 26, 2025

@nickfloyd Would there be any value in having some kind of regression test for that scenario? Maybe it could be used in the future to ensure other resources don't end up in a similar situation?

@nickfloyd
Copy link
Copy Markdown
Member

@nickfloyd Would there be any value in having some kind of regression test for that scenario? Maybe it could be used in the future to ensure other resources don't end up in a similar situation?

I'm always up for more tests 😉. I think the main challenge here is that, currently our testing suite does not handle integration or e2e scenarios very well. So when testing we have to use a real org and in this case one that has org rulesets.

I know @stevehipwell has been working to make that whole experience better as well.

@nickfloyd nickfloyd self-requested a review December 1, 2025 17:58
@nickfloyd nickfloyd dismissed diofeher’s stale review December 1, 2025 17:58

I updated the PR notes.

@nickfloyd
Copy link
Copy Markdown
Member

Verified with:

terraform import github_organization_ruleset.test 999999999

terraform {
  required_providers {
    github = {
      source  = "integrations/github"
      version = "99.0.0" 
    }
  }
}

provider "github" {
  owner = "integrations"
}

# Using a non-existent ID 999999999
resource "github_organization_ruleset" "test" {
  name        = "test-ruleset"
  target      = "branch"
  enforcement = "disabled"

  conditions {
    ref_name {
      include = ["~ALL"]
      exclude = []
    }
  }

  rules {
    creation = true
  }
}

output "test" {
  value = "Testing PR #2705 fix"
}

Returns a 404 and not a segfault now.

@nickfloyd nickfloyd merged commit 891b28e into integrations:main Dec 1, 2025
8 checks passed
@github-project-automation github-project-automation bot moved this from In Review to Done in Terraform Provider Dec 1, 2025
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in 🧰 Octokit Active Dec 1, 2025
@stevehipwell
Copy link
Copy Markdown
Collaborator

@nickfloyd this is an instance of the defective error pattern I mentioned on an issue/PR the other week. I think we need to get a general issue open to track resolving the other places where this pattern is present.

@nickfloyd
Copy link
Copy Markdown
Member

@nickfloyd this is an instance of the defective error pattern I mentioned on an issue/PR the other week. I think we need to get a general issue open to track resolving the other places where this pattern is present.

Agreed. I'll try to put an issue together shortly, unless you get to it before I do.

@stevehipwell
Copy link
Copy Markdown
Collaborator

@nickfloyd I've created #2957.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

[BUG]: Refreshing github_organization_ruleset crashes Terraform plugin with segfault

6 participants