How can a plugin return a specific error message for display at the GUI?
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?
-
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);
}
}
Please sign in to leave a comment.
Comments
2 comments