Skip to content

fix: missing error returns#2962

Merged
nickfloyd merged 15 commits intomainfrom
2957-fix-missing-error-returns
Dec 4, 2025
Merged

fix: missing error returns#2962
nickfloyd merged 15 commits intomainfrom
2957-fix-missing-error-returns

Conversation

@nickfloyd
Copy link
Copy Markdown
Member

@nickfloyd nickfloyd commented Dec 3, 2025

Resolves #2957
Relates to: #2705


Before the change?

  • When an error is returned from the GitHub API it should result in a provider error unless the behavior is explicitly expected and coded for.

After the change?

Added catch all for:

  • resource_github_user_ssh_key.go

Pull request checklist

  • Schema migrations have been created if needed (example)
  • 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

@nickfloyd nickfloyd added this to the v6.x version wrap up milestone Dec 3, 2025
@nickfloyd nickfloyd self-assigned this Dec 3, 2025
@nickfloyd nickfloyd added the Type: Bug Something isn't working as documented label Dec 3, 2025
@nickfloyd nickfloyd moved this from Backlog to In Review in Terraform Provider Dec 3, 2025
@stevehipwell
Copy link
Copy Markdown
Collaborator

I'm not sure all of these need the extra return as it looks like they're falling through to an error return outside of the type check. Basically the pattern looks subtly different to the ones we saw for the rulesets. I'm on my phone so will look again in the morning on a big screen to double check.

d.SetId("")
return nil
}
return err
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This one looks redundant, since we already have return err below.

}
return err
}
return err
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is the only one that doesn't return a redundant error on this PR, I think. But I would still remove the return err above.

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.

From what I'm checking in a quick glance, it seems most of these returns are redundants, as there's no code path after the if and most of them falls to the return err below. Can you double-check if that's true?

EDIT: I just saw @stevehipwell's comments, and I mostly agree with him.

@nickfloyd
Copy link
Copy Markdown
Member Author

@stevehipwell @diofeher let me do another sweep to make sure I didn't over index on my search of missing instances. Thx for the quick 👀

Copy link
Copy Markdown
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

I think you've got the obviously broken one and it looks like the other instances have already been cleaned up. I did spot the following related patterns that aren't idiomatic (using else where it's not required) and could do with being cleaned up.

if err != nil {
return err
}
} else {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

question: it looks like the else might be redundant here or are there legitimate use-case where it's fine to swallow err?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think there is. When create fails but update succeeds.

Copy link
Copy Markdown
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

LGTM

@nickfloyd nickfloyd merged commit 77035e6 into main Dec 4, 2025
8 checks passed
@github-project-automation github-project-automation bot moved this from In Review to Done in Terraform Provider Dec 4, 2025
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

Development

Successfully merging this pull request may close these issues.

[BUG]: Fix missing return when using errors.As

4 participants