Class RuleExecutionException

All Implemented Interfaces:
Serializable

public class RuleExecutionException extends UnrulyException
Thrown by run() when a run fails: because a rule's condition or action failed, or because something outside any rule did.

getRuleName() and getExpressionKind() name the rule and the expression when a condition or action threw, a condition evaluated to something other than a Boolean, an action returned null, or a property an action returned couldn't be set on the output. A fatal Error a listener's beforeEvaluate or beforeExecute callback threw names the rule but no expression. Both are null for a failure that belongs to no rule:

  • the run was interrupted, or passed its deadline, while it waited for a compiled copy of the rules, or while it read them again after a reload, or a close of the engine, closed the list it had read;
  • the run was stopped between rules, or when a condition or action returned, or threw something with no Error anywhere in its cause chain, nor one suppressed on it at any depth, once the run had to stop, because its thread was interrupted or it passed its deadline; the cause is then an InterruptedException or a TimeoutException. An InterruptedException in the cause chain of what it threw, or suppressed there, sets the interrupt status again first, so such a throw stops the run as interrupted. One that threw something with an Error in its cause chain, or suppressed on it at any depth, is that rule's own failure instead, so both getRuleName() and getExpressionKind() are set and the cause is what the expression threw;
  • more than one rule matched on a unique-match engine, which the message names;
  • the output supplier threw or returned null;
  • a language threw or returned null when it created a session for the run;
  • a fatal Error left the run from the output supplier, from a language's check of a fact name, or from a listener's beforeRun, afterEvaluate or afterExecute callback: then run() rethrows the error itself, and this exception, which carries it, goes to RuleListener.onRunError(io.github.brantunger.unruly.api.RunContext, java.lang.RuntimeException). One from afterRun is rethrown with no exception and no callback.
See Also:
  • Constructor Details

    • RuleExecutionException

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

      public RuleExecutionException(@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
    • RuleExecutionException

      public RuleExecutionException(@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
    • RuleExecutionException

      public RuleExecutionException(@Nullable String message, @Nullable Throwable cause, @Nullable String ruleName, @Nullable ExpressionKind expressionKind)
      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 failure isn't about one rule or the rule has no name
      expressionKind - Whether the condition or the action failed, or null if neither did
  • 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 the output supplier failed, or the run was stopped)
    • 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 listener or the output supplier failed