Exemplo n.º 1
0
 public static ExprValidationException MakeValidationExWExpression(
     ExprNodeOrigin origin,
     String text,
     ExprValidationException ex)
 {
     return new ExprValidationException(
         $"Failed to validate {origin.GetClauseName()} expression {text}: {ex.Message}",
         ex);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Validates the expression node subtree that has this
        /// node as root. Some of the nodes of the tree, including the
        /// root, might be replaced in the process.
        /// </summary>
        /// <param name="origin">validate origin</param>
        /// <param name="exprNode">node</param>
        /// <param name="validationContext">context</param>
        /// <returns>the root node of the validated subtree, possibly different than the root node of the unvalidated subtree
        /// </returns>
        /// <throws>ExprValidationException when the validation fails</throws>
        public static ExprNode GetValidatedSubtree(
            ExprNodeOrigin origin,
            ExprNode exprNode,
            ExprValidationContext validationContext)
        {
            if (exprNode is ExprLambdaGoesNode) {
                return exprNode;
            }

            try {
                return GetValidatedSubtreeInternal(exprNode, validationContext, true);
            }
            catch (ExprValidationException ex) {
                try {
                    string text;
                    if (exprNode is ExprSubselectNode subselect) {
                        text = ExprNodeUtilityMake.GetSubqueryInfoText(subselect);
                    }
                    else {
                        text = ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(exprNode);
                        if (text.Length > 40) {
                            string shortened = text.Substring(0, 35);
                            text = shortened + "...(" + text.Length + " chars)";
                        }

                        text = "'" + text + "'";
                    }

                    var errorText = string.Format(
                        "Failed to validate {0} expression {1}: {2}",
                        origin.GetClauseName(),
                        text,
                        ex.Message);

                    throw new ExprValidationException(errorText, ex);
                }
                catch (ExprValidationException) {
                    throw;
                }
                catch (EPException) {
                    throw;
                }
                catch (Exception rtex) {
                    Log.Debug("Failed to render nice validation message text: " + rtex.Message, rtex);
                    // fall through
                }

                throw;
            }
        }
Exemplo n.º 3
0
 private static void ValidatePlainExpression(
     ExprNodeOrigin origin,
     ExprNode expression,
     ExprNodeSummaryVisitor summaryVisitor)
 {
     expression.Accept(summaryVisitor);
     if (summaryVisitor.HasAggregation ||
         summaryVisitor.HasSubselect ||
         summaryVisitor.HasStreamSelect ||
         summaryVisitor.HasPreviousPrior) {
         string text = ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(expression);
         throw new ExprValidationException(
             "Invalid " +
             origin.GetClauseName() +
             " expression '" +
             text +
             "': Aggregation, sub-select, previous or prior functions are not supported in this context");
     }
 }