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.
While playing with a CloudBees CI setup configured as code, I noticed to my alarm that when a sample Git repository was offline, Jenkins startup failed:
It turns out that there was nothing really wrong in the proprietary plugin:
GlobalTemplateCatalogConfigurator.configure
was catching anIOException
thrown fromSCMSource.fetch
and proceeding. UnfortunatelyAbstractGitSCMSource.retrieve
was passing along aGitException
thrown from aGitClient
method as is, without wrapping in a declared exception permitted by the interface inscm-api
.While I could have fixed merely this call site, once I started looking I found that the problem was fairly general in this plugin: in a number of places it is implementing APIs from core or
scm-api
which permitIOException
but throwing this unchecked exception. So I decided to fix the general issue. If desired, this PR could be broken up and fixes to just those methods filed separately, though for legibility I find it helpful to be documenting whereGitException
is thrown.Initially developed by manually looking up usages of
GitClient
methods throwingGitException
and checking their call sites, but it proved much easier to use jenkinsci/git-client-plugin#1166 withGitException
checked and fix all compiler errors. My general principle is to just keeping addingthrows GitException
as needed until coming up to an interface defined in a dependency which does not allow it, and at that point wrapping it. Note that a number of places in the plugin already caughtGitException
, though generally printing an error to aTaskListener
and then signaling some sort of failure separately rather than using it as acause
.