GoogleContainerTools / GoogleContainerTools/jib
Better way to handle invalid configuration values to show error messages
- Dominant language
- Java
- Stars
- 14.5k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
`PluginConfigurationProcessor` throws many exceptions.
```
throws InvalidImageReferenceException, MainClassInferenceException, InvalidAppRootException,
IOException, InvalidWorkingDirectoryException, InvalidContainerVolumeException,
IncompatibleBaseImageJavaVersionException, NumberFormatException,
InvalidContainerizingModeException, InvalidFilesModificationTimeException {
```
Many exceptions are only for syntactically invalid config values, but not all of them. Plugin code handles these exceptions in long catch blocks. Sometimes we use `HelpfulSuggestions` for error messages, but sometimes not. This long blocks are being copied over three tasks (build, dockerBuild, buildTar). I honestly don't know how we can best handle this.
details (click to unfold)
```java
} catch (InvalidContainerizingModeException ex) {
throw new MojoExecutionException(
"invalid value for : " + ex.getInvalidContainerizingMode(), ex);
} catch (InvalidWorkingDirectoryException ex) {
throw new MojoExecutionException(
" is not an absolute Unix-style path: "
+ ex.getInvalidPathValue(),
ex);
} catch (InvalidContainerVolumeException ex) {
throw new MojoExecutionException(
" is not an absolute Unix-style path: " + ex.getInvalidVolume(), ex);
} catch (InvalidFilesModificationTimeException ex) {
throw new MojoExecutionException(
" should be an ISO 8601 date-time (see "
+ "DateTimeFormatter.ISO_DATE_TIME) or special keyword \"EPOCH_PLUS_SECOND\": "
+ ex.getInvalidFilesModificationTime(),
ex);
} catch (IncompatibleBaseImageJavaVersionException ex) {
throw new MojoExecutionException(
HelpfulSuggestions.forIncompatibleBaseImageJavaVesionForMaven(
ex.getBaseImageMajorJavaVersion(), ex.getProjectMajorJavaVersion()),
ex);
} catch (InvalidImageReferenceException ex) {
throw new MojoExecutionException(
HelpfulSuggestions.forInvalidImageReference(ex.getInvalidReference()), ex);
} catch (IOException | CacheDirectoryCreationException | MainClassInferenceException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
} catch (BuildStepsExecutionException ex) {
throw new MojoExecutionException(ex.getMessage(), ex.getCause());
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.