OCPERT-319: Rename JenkinsException to JenkinsHelperException to avoid naming conflict#899
Conversation
…d naming conflict Rename custom exception to avoid shadowing jenkins library's JenkinsException, fixing both import conflicts and bare except anti-pattern. Changes: - Rename JenkinsException to JenkinsHelperException in oar/core/exceptions.py - Update oar/core/jenkins.py to properly catch both jenkins API exceptions and our custom helper exceptions - Fix bare 'except:' on line 186 to explicitly catch exceptions - Update all raise statements to use JenkinsHelperException - Update exception handlers to catch (JenkinsException, JenkinsHelperException) - Update oar/cli/cmd_stage_testing.py import and usage - Update oar/cli/cmd_image_consistency_check.py import and usage (2 locations) Exception handling pattern: - CATCH: JenkinsException (from jenkins library API calls) OR JenkinsHelperException (from our code) - RAISE: Always JenkinsHelperException (our custom exception) This fixes: 1. Import name shadowing (jenkins.JenkinsException was inaccessible) 2. Bare 'except:' anti-pattern that caught system signals 3. Unclear exception handling (now explicit about what we catch) Related: openshift#897, openshift#898
|
@rioliu-rh: This pull request references OCPERT-319 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 story to target the "4.22.0" version, but no target version was set. DetailsIn response to this:
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. |
1 similar comment
|
@rioliu-rh: This pull request references OCPERT-319 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 story to target the "4.22.0" version, but no target version was set. DetailsIn response to this:
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. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
@rioliu-rh: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions 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. I understand the commands that are listed here. |
Summary
Final cleanup for OCPERT-319 exception refactoring: Rename custom
JenkinsExceptiontoJenkinsHelperExceptionto avoid naming conflict with the jenkins library's exception class.This PR fixes two issues discovered after #897 and #898:
JenkinsExceptionwas inaccessibleexcept:anti-pattern - Line 186 in jenkins.py used bare except to work around the shadowing issueRoot Cause
The original code had:
This meant:
jenkins.JenkinsException(from the library)except:to catch everythingChanges
1. Rename Exception Class
JenkinsException→JenkinsHelperException2. Fix oar/core/jenkins.py (7 locations)
JenkinsHelperException(our custom exception)from jenkins import JenkinsException(jenkins library - no longer shadowed)JenkinsHelperException(JenkinsException, JenkinsHelperException)JenkinsException- from jenkins library API callsJenkinsHelperException- from our own codeexcept:on line 186:3. Update CLI Commands
Exception Handling Pattern
The new pattern is explicit and clear:
Benefits
from eto preserve exception contextTesting
Related: #897, #898