Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

User input should be validated as early as possible. Anything static should be validated in the configurePipeline() method. Everything else should be validated in the prepareRun() method.One convention many plugins have used is to have a validate() method on their plugin config object. Sometimes it will take an input schema as an argument. That way the validate() method can easily be called at configure time and at prepare time. It also gives a way to quickly unit test the validation logic without needing to deploy pipelines., which means in the configurePipeline() method.

Some useful things to keep in mind while validating:

  • Use the containsMacro() method to check if the property is ready to be validated
  • If a property is invalid, throw an IllegalArgumentException InvalidConfigPropertyException with a user friendly message. This message will be shown in the UI and should mention which property is invalid, why it is invalid, and what action the user can take to make it valid.
  • If multiple properties are invalid, throw an InvalidStagePropertyException that contains multiple exceptions are the reasons.
  • For numeric properties, can the property be 0? Can it be negative? Does it need to be within a certain range?
  • The input schema is often required to perform validation. For example, a plugin may operate on a specific field, which can only be a specific type.
  • A property cannot be null unless it is annotated asĀ @Nullable.
  • Don't forget to handle empty strings.

...