log appropriate error messages to build console#759
Merged
Conversation
…es' into issue_702_log_appropriate_messages
- Catch specific exceptions rather than catching general Exception
…essages * master: Bump org.jenkins-ci.plugins:plugin from 5.26 to 5.28 in the jenkins group (#753)
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves error handling and logging by replacing TimeoutException with RestClientException throughout the JIRA plugin, ensuring that appropriate error messages are logged to the build console when REST API calls fail.
Key Changes:
- Replaced
TimeoutExceptionwithRestClientExceptionin method signatures and exception handling across the codebase - Added try-catch blocks in pipeline steps and build steps to catch
RestClientExceptionand log error messages to the build console - Modified
JiraRestServiceto throwRestClientExceptionwith descriptive messages instead of returning null or empty collections on errors
Reviewed changes
Copilot reviewed 29 out of 29 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/hudson/plugins/jira/JiraRestService.java | Core change: throws RestClientException with descriptive messages instead of returning null/empty collections |
| src/main/java/hudson/plugins/jira/JiraSession.java | Updated method signatures to throw RestClientException instead of TimeoutException |
| src/main/java/hudson/plugins/jira/JiraSite.java | Added RestClientException handling and updated method signatures |
| src/main/java/hudson/plugins/jira/pipeline/*.java | Added try-catch blocks to log RestClientException messages to console in SearchIssuesStep, IssueSelectorStep, IssueFieldUpdateStep, and CommentStep |
| src/main/java/hudson/plugins/jira/JiraIssueUpdateBuilder.java | Changed exception handling from TimeoutException to RestClientException |
| src/main/java/hudson/plugins/jira/JiraEnvironmentVariableBuilder.java | Added try-catch to handle RestClientException and log to console |
| src/main/java/hudson/plugins/jira/JiraCreateIssueNotifier.java | Wrapped build result handling in try-catch for RestClientException |
| src/main/java/hudson/plugins/jira/JiraJobAction.java | Added RestClientException to catch block |
| src/main/java/hudson/plugins/jira/Updater.java | Removed RestClientException from method signature and simplified error logging |
| src/main/java/hudson/plugins/jira/selector/JqlIssueSelector.java | Changed exception type from TimeoutException to RestClientException |
| src/main/java/hudson/plugins/jira/*ParameterDefinition.java | Updated method signatures to include RestClientException |
| src/test/java/hudson/plugins/jira/pipeline/*.java | Added comprehensive tests for REST exception handling in pipeline steps |
| src/test/java/hudson/plugins/jira/*.java | Added tests for exception logging and updated existing tests to use RestClientException |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
src/test/java/hudson/plugins/jira/JiraEnvironmentVariableBuilderTest.java
Outdated
Show resolved
Hide resolved
Comment on lines
+146
to
+152
| doThrow(new RestClientException("[Jira] Jira REST findIsusueIds error. Cause: 401 error", throwable)) | ||
| .when(issueSelector) | ||
| .findIssueIds(build, site, listener); | ||
| JiraEnvironmentVariableBuilder builder = spy(new JiraEnvironmentVariableBuilder(issueSelector)); | ||
| doReturn(site).when(builder).getSiteForProject(project); | ||
| assertThat(builder.perform(build, launcher, listener), is(false)); | ||
| verify(logger).println("[Jira] Jira REST findIsusueIds error. Cause: 401 error"); |
There was a problem hiding this comment.
Typo in error message: "findIsusueIds" should be "findIssueIds".
Suggested change
| doThrow(new RestClientException("[Jira] Jira REST findIsusueIds error. Cause: 401 error", throwable)) | |
| .when(issueSelector) | |
| .findIssueIds(build, site, listener); | |
| JiraEnvironmentVariableBuilder builder = spy(new JiraEnvironmentVariableBuilder(issueSelector)); | |
| doReturn(site).when(builder).getSiteForProject(project); | |
| assertThat(builder.perform(build, launcher, listener), is(false)); | |
| verify(logger).println("[Jira] Jira REST findIsusueIds error. Cause: 401 error"); | |
| doThrow(new RestClientException("[Jira] Jira REST findIssueIds error. Cause: 401 error", throwable)) | |
| .when(issueSelector) | |
| .findIssueIds(build, site, listener); | |
| JiraEnvironmentVariableBuilder builder = spy(new JiraEnvironmentVariableBuilder(issueSelector)); | |
| doReturn(site).when(builder).getSiteForProject(project); | |
| assertThat(builder.perform(build, launcher, listener), is(false)); | |
| verify(logger).println("[Jira] Jira REST findIssueIds error. Cause: 401 error"); |
src/test/java/hudson/plugins/jira/pipeline/IssueFieldUpdateStepTest.java
Show resolved
Hide resolved
src/test/java/hudson/plugins/jira/pipeline/IssueFieldUpdateStepTest.java
Show resolved
Hide resolved
src/test/java/hudson/plugins/jira/pipeline/IssueFieldUpdateStepTest.java
Show resolved
Hide resolved
src/test/java/hudson/plugins/jira/pipeline/IssueFieldUpdateStepTest.java
Show resolved
Hide resolved
src/test/java/hudson/plugins/jira/pipeline/IssueFieldUpdateStepTest.java
Show resolved
Hide resolved
src/test/java/hudson/plugins/jira/pipeline/IssueFieldUpdateStepTest.java
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pick up #711 by @Hardikrathod01 and resolve conflicts.
Related issues
#702
#711
Changes
See #711
Tests
Checklist
featureorbugfixordocumentation