How can a plugin return a specific error message for display at the GUI?

1 follower
0
Avatar

The SDK documentation shows that the main action of a plugin has to take place in a class which implements a ValueComputor interface. The methods which have to be implemented are compute(), computeIntermediate(), computeFinal(), etc. depending on the underlying interface type. The definition of these methods does not include any exception throwing. So, how can a plugin return a specific error message back to its caller so that it can be displayed at the GUI?

 

 

Jutta Lachfeld

2 comments

  • Avatar
    Gido

    You could either throw a runtime exception with your own message or use Preconditons. Please find a small example for how to check two input arguments and return an error message if the second argument is not of the same type:

    import datameer.com.google.common.base.Preconditions;

    public void validateArgumentTypes(ArgumentInfo arguments) {
    super.validateArgumentTypes(arguments);
    if (arguments.getNumArguments() == 2) {
    ValueType returnType = computeReturnSchemaType(arguments);
    ValueType second = arguments.getType(1);
    Preconditions.checkArgument(second.matches(returnType.getValueTypeId()), "Argument 2 must be of type " + returnType);
    }
    }
    0
  • Avatar
    Jutta Lachfeld

    Thanks! Throwing a RuntimeException does it. Will keep the Preconditions in mind for later use.

    0
Please sign in to leave a comment.