Class RuleCompilationException

All Implemented Interfaces:
Serializable

public class RuleCompilationException extends UnrulyException
Exception thrown when a rule fails to compile, or when several do.

RulesEngine.load(java.util.List) compiles every rule before it throws, so one exception reports everything that failed: failures() has one exception for each broken rule, for a language that couldn't create its compiler and for each declared fact name the languages reject, and the name, expression kind and issues of this exception are those of the first. A failure that isn't a rule's has no rule name.

See Also:
  • Constructor Details

    • RuleCompilationException

      public RuleCompilationException(@Nullable String message)
      Constructs a new exception with the specified detail message.
      Parameters:
      message - The detail message
    • RuleCompilationException

      public RuleCompilationException(@Nullable String message, @Nullable Throwable cause)
      Constructs a new exception with the specified detail message and cause.
      Parameters:
      message - The detail message
      cause - The cause
    • RuleCompilationException

      public RuleCompilationException(@Nullable String message, @Nullable Throwable cause, @Nullable String ruleName)
      Constructs a new exception with the specified detail message, cause and the name of the rule that failed.
      Parameters:
      message - The detail message
      cause - The cause
      ruleName - The name of the rule that failed, or null if the failure isn't about one rule or the rule has no name
    • RuleCompilationException

      public RuleCompilationException(@Nullable String message, @Nullable Throwable cause, @Nullable String ruleName, @Nullable ExpressionKind expressionKind, List<InvalidExpressionException.Issue> issues)
      Constructs a new exception for one rule's condition or action.
      Parameters:
      message - The detail message
      cause - The cause
      ruleName - The name of the rule that failed, or null if the rule has no name
      expressionKind - Whether the condition or the action failed, or null if neither did
      issues - Where and what the expression language found wrong; copied
      Throws:
      NullPointerException - if issues or one of its elements is null
    • RuleCompilationException

      public RuleCompilationException(@Nullable String message, List<RuleCompilationException> failures)
      Constructs an exception for several failures while loading a rule list. Its rule name, expression kind and issues are those of the first failure, which is also its cause.
      Parameters:
      message - The detail message
      failures - Each failure, in the order they were found; copied
      Throws:
      IllegalArgumentException - if failures is empty
      NullPointerException - if failures or one of its elements is null
  • Method Details

    • getRuleName

      public @Nullable String getRuleName()
      Returns the name of the rule that failed, as Rule.getRuleName() returns it. Unlike the message, it isn't escaped or shortened, so it can be used to look the rule up.
      Returns:
      The rule's name, or null if the failure isn't about one rule (for example an expression language failed to create its compiler, or an element of the list is null)
    • getExpressionKind

      public @Nullable ExpressionKind getExpressionKind()
      Returns whether the rule's condition or its action failed.
      Returns:
      The kind of expression, or null if the failure isn't about a condition or an action, for example a rule written in a language the engine doesn't have
    • issues

      Returns where and what the expression language found wrong, when it said.
      Returns:
      The issues, possibly none; unmodifiable
    • failures

      public List<RuleCompilationException> failures()
      Returns every failure of the load, in the order they were found: each broken rule's, in priority order; a language that couldn't create its compiler, in place of the first rule that needed it; and each declared fact name the languages reject, last. Only a rule's failure has a rule name.
      Returns:
      One exception for each failure, or only this exception if there was one; unmodifiable