Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better way to handle invalid configuration values to show error messages #1868

Open
chanseokoh opened this issue Jul 24, 2019 · 1 comment
Open

Comments

@chanseokoh
Copy link
Member

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)
    } catch (InvalidContainerizingModeException ex) {
      throw new MojoExecutionException(
          "invalid value for <containerizingMode>: " + ex.getInvalidContainerizingMode(), ex);

    } catch (InvalidWorkingDirectoryException ex) {
      throw new MojoExecutionException(
          "<container><workingDirectory> is not an absolute Unix-style path: "
              + ex.getInvalidPathValue(),
          ex);

    } catch (InvalidContainerVolumeException ex) {
      throw new MojoExecutionException(
          "<container><volumes> is not an absolute Unix-style path: " + ex.getInvalidVolume(), ex);

    } catch (InvalidFilesModificationTimeException ex) {
      throw new MojoExecutionException(
          "<container><filesModificationTime> 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());
    }
  }
@TadCordle
Copy link
Contributor

I've been thinking about this a bit, and I have a couple ideas:

  1. Just do straightforward code reduction. catch(Exception ex) and pass ex into a method in TaskCommon/MojoCommon that checks the type and rethrows with the message we want, and if it's not a type we know, throw ex. This doesn't help with PluginConfigurationProcessor throwing so many exceptions, but it's an easy way of reducing a decent amount of duplicate code.

  2. Do something like remove all these custom exception classes and put all the failures under a JibPluginException that just takes a message. Maybe we can move all the messages we'd pass to it into HelpfulSuggestions to unify things a bit better. But this might either increase the number of parameters we need to pass into HelpfulSuggestions (since maven and gradle have different terminology, parameter names, etc.), or require us to make HelpfulSuggestions an interface with a maven and gradle implementation.

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

No branches or pull requests

3 participants