kfaraz commented on code in PR #16470: URL: https://github.com/apache/druid/pull/16470#discussion_r1606214201
########## processing/src/main/java/org/apache/druid/error/InvalidInput.java: ########## @@ -35,6 +35,37 @@ public static DruidException exception(Throwable t, String msg, Object... args) return DruidException.fromFailure(new InvalidInput(t, msg, args)); } + /** + * evalues a condition. If it's false, it throws the appropriate DruidException + * + * @param condition - boolean condition to validate + * @param msg - passed through to InvalidInput.exception() + * @param args - passed through to InvalidInput.exception() + */ + public static void conditionalException(boolean condition, String msg, Object... args) Review Comment: I think a better syntax would be one similar to the `Preconditions` thing. We could have a static utility class named `DruidConditions` or similar. It could contain methods like `checkInputCondition` (or `validateInputCondition` if preferred), `checkInputNotNull`, `checkDefensiveCondition`, etc. Usage would be: ```java Object validatedInput = DruidConditions.checkInputNotNull(input, "[%s] must be non-null", fieldName); DruidConditions.checkInputCondition(input > 100, "[%s] must be greater than [100]", fieldName); DruidConditions.checkDefensiveCondition(3 > 2, "3 must always be greater than 2"); ``` Pros: - self-explanatory nomenclature - all condition checks live in one class - calling code does not have to import a bunch of different exceptions if it does several different kinds of validations - easier for contributors too -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org