java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
software.amazon.smithy.rulesengine.language.error.RuleError
All Implemented Interfaces:
Serializable

public final class RuleError extends RuntimeException
An exception that can be thrown when a rule-set is invalid.

Used for providing meaningful contextual information when an invalid rule-set is encountered.

See Also:
  • Constructor Details

    • RuleError

      public RuleError(SourceException root)
      Constructs a new RuleError from the source exception.
      Parameters:
      root - the exception this rule error is based on.
  • Method Details

    • context

      public static void context(String message, Runnable runnable)
      Evaluates the runnable and creates a RuleError with the provided context if there's an error.
      Parameters:
      message - a message representing the context for this runnable statement's evaluation.
      runnable - a runnable to evaluate a statement in the current context.
    • context

      public static <T> T context(String message, RuleError.Evaluator<T> runnable) throws RuleError
      Evaluates the runnable and creates a RuleError with the provided context if there's an error.
      Type Parameters:
      T - the type of the value returned by the runnable.
      Parameters:
      message - a message representing the context for this runnable statement's evaluation.
      runnable - a runnable to evaluate a statement in the current context.
      Returns:
      the value returned by the runnable.
      Throws:
      RuleError - when the rule being evaluated in the context fails.
    • context

      public static void context(String message, FromSourceLocation sourceLocation, Runnable runnable)
      Evaluates the runnable and creates a RuleError with the provided context if there's an error.
      Parameters:
      message - a message representing the context for this runnable statement's evaluation.
      sourceLocation - the source location for this runnable statement's evaluation.
      runnable - a runnable to evaluate a statement in the current context.
    • context

      public static <T> T context(String message, FromSourceLocation sourceLocation, RuleError.Evaluator<T> runnable) throws RuleError
      Evaluates the runnable and creates a RuleError with the provided context if there's an error.
      Type Parameters:
      T - the type of the value returned by the runnable.
      Parameters:
      message - a message representing the context for this runnable statement's evaluation.
      sourceLocation - the source location for this runnable statement's evaluation.
      runnable - a runnable to evaluate a statement in the current context.
      Returns:
      the value returned by the runnable.
      Throws:
      RuleError - when the rule being evaluated in the context fails.
    • withContext

      public RuleError withContext(String context, SourceLocation location)
      Sets a piece of context on this error.
      Parameters:
      context - the context to add to the error.
      location - the source location of the context being added.
      Returns:
      returns this error with the added context.
    • toString

      public String toString()
      Overrides:
      toString in class Throwable