This is an automated email from the ASF dual-hosted git repository. heneveld pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
commit a67de70822b38198ed99af460caff57664130772 Author: Alex Heneveld <[email protected]> AuthorDate: Fri Mar 24 10:56:20 2023 +0000 add message for mathematical operations without spaces --- .../steps/variables/SetVariableWorkflowStep.java | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/apache/brooklyn/core/workflow/steps/variables/SetVariableWorkflowStep.java b/core/src/main/java/org/apache/brooklyn/core/workflow/steps/variables/SetVariableWorkflowStep.java index 44e4969fbc..82f7c3ac66 100644 --- a/core/src/main/java/org/apache/brooklyn/core/workflow/steps/variables/SetVariableWorkflowStep.java +++ b/core/src/main/java/org/apache/brooklyn/core/workflow/steps/variables/SetVariableWorkflowStep.java @@ -317,16 +317,28 @@ public class SetVariableWorkflowStep extends WorkflowStepDefinition { Maybe<Double> rhsD = asDouble(rhs); if (lhsD.isPresent() && rhsD.isPresent()) return asDouble(ifDouble.apply(lhsD.get(), rhsD.get())).get(); - if (lhsD.isAbsent()) throw new IllegalArgumentException("Invalid left argument to operation '"+op+"': "+lhs0+" => "+lhs); - if (rhsD.isAbsent()) throw new IllegalArgumentException("Invalid right argument to operation '"+op+"': "+rhs0+" = "+rhs); + if (lhsD.isAbsent()) failOnInvalidArgument("left", op, lhs0, lhs); + if (rhsD.isAbsent()) failOnInvalidArgument("right", op, rhs0, rhs); + } else { + if (lhsI.isAbsent()) failOnInvalidArgument("left", op, lhs0, lhs); + if (rhsI.isAbsent()) failOnInvalidArgument("right", op, rhs0, rhs); } - if (lhsI.isAbsent()) throw new IllegalArgumentException("Invalid left argument to operation '"+op+"': "+lhs0+" => "+lhs); - if (rhsI.isAbsent()) throw new IllegalArgumentException("Invalid right argument to operation '"+op+"': "+rhs0+" = "+rhs); - throw new IllegalArgumentException("Should not come here"); } + private IllegalArgumentException failOnInvalidArgument(String side, String op, Object pre, Object post) { + String msg = "Invalid "+side+" argument to operation '"+op+"'"; + + String postS = ""+post; + if (postS.contains("*") || postS.contains("+") || postS.contains("+") || postS.contains("/")) { + // we could weaken this contraint but for now at least make it clear + msg += "; mathematical operations must have spaces around them for disambiguation"; + } + + throw new IllegalArgumentException(msg + ": "+pre+" => "+post); + } + Object handleMultiply(List<String> lhs, List<String> rhs) { return applyMathOperator("*", lhs, rhs, (a,b)->a*b, (a,b)->a*b); }
