Skip to content

CNF-23579: Replace panics with error returns in production code#1203

Open
sebrandon1 wants to merge 1 commit into
ComplianceAsCode:masterfrom
sebrandon1:replace-panics-with-errors
Open

CNF-23579: Replace panics with error returns in production code#1203
sebrandon1 wants to merge 1 commit into
ComplianceAsCode:masterfrom
sebrandon1:replace-panics-with-errors

Conversation

@sebrandon1
Copy link
Copy Markdown

Summary

  • Replace 4 panic() calls in non-test production code with proper error handling
  • saveScanResult in cel-scanner.go now returns error; caller logs and exits with CelExitCodeError
  • GetScanType and GetScannerType now return (T, error) instead of panicking
  • getTargetNodes in scantype.go propagates the error from GetScanType

Test plan

  • go build ./... passes
  • go vet ./... passes
  • Unit tests pass for pkg/apis/compliance/v1alpha1 and pkg/controller/compliancescan

Four panic() calls in non-test code crash the process for recoverable
errors. Replace them with proper error handling:

- cel-scanner.go: saveScanResult now returns error; caller logs and
  exits with CelExitCodeError, matching every other error path in
  runPlatformScan.
- compliancescan_types.go: GetScanType and GetScannerType now return
  (T, error) instead of panicking, delegating to the IfValid variants.
- scantype.go: getTargetNodes propagates the error from GetScanType.
@openshift-ci openshift-ci Bot requested review from jhrozek and yuumasato May 6, 2026 18:32
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented May 6, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sebrandon1
Once this PR has been reviewed and has the lgtm label, please assign mrogers950 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented May 6, 2026

Hi @sebrandon1. Thanks for your PR.

I'm waiting for a ComplianceAsCode member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

🤖 To deploy this PR, run the following command:

make catalog-deploy CATALOG_IMG=ghcr.io/complianceascode/compliance-operator-catalog:1203-d5b1ea8dc5161e7d122a0de30e2aeccadf6a6ca8

@sebrandon1 sebrandon1 changed the title Replace panics with error returns in production code CNF-23579: Replace panics with error returns in production code May 6, 2026
@openshift-ci-robot
Copy link
Copy Markdown
Collaborator

@sebrandon1: This pull request references CNF-23579 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Summary

  • Replace 4 panic() calls in non-test production code with proper error handling
  • saveScanResult in cel-scanner.go now returns error; caller logs and exits with CelExitCodeError
  • GetScanType and GetScannerType now return (T, error) instead of panicking
  • getTargetNodes in scantype.go propagates the error from GetScanType

Test plan

  • go build ./... passes
  • go vet ./... passes
  • Unit tests pass for pkg/apis/compliance/v1alpha1 and pkg/controller/compliancescan

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants