Skip to content

reduce scope of try-catch - #45

Open
frhanjav wants to merge 1 commit into
jenkinsci:mainfrom
frhanjav:scope-optimize
Open

reduce scope of try-catch#45
frhanjav wants to merge 1 commit into
jenkinsci:mainfrom
frhanjav:scope-optimize

Conversation

@frhanjav

@frhanjav frhanjav commented Mar 8, 2025

Copy link
Copy Markdown

What does this PR do?

Fixes #25

Type of Change

The PR fixes an efficiency issue in the captureEvent(FlowNode node) method by reducing the scope of the try-catch block.

Previously, the entire chain of method calls was wrapped in a try-catch, but only getExecutable() actually throws IOException.

The solution extracts node.getExecution().getOwner() out of the try-catch block and stores the result in a properly typed variable (FlowExecutionOwner owner), then only wraps the owner.getExecutable() call in the exception handling. This makes the code more readable and precisely identifies which operation might fail.

The correct type was identified by consulting the Jenkins API documentation at:
https://javadoc.jenkins.io/plugin/workflow-api/org/jenkinsci/plugins/workflow/flow/FlowExecution.html
which shows that method getOwner() returns a FlowExecutionOwner type

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimizing code to make it more readable and easier to debug

1 participant