Class ConfigValidationException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
io.github.jspinak.brobot.runner.json.validation.exception.ConfigValidationException
All Implemented Interfaces:
Serializable

public class ConfigValidationException extends RuntimeException
Exception thrown when Brobot configuration validation fails.

This exception provides detailed information about validation failures, including the specific errors, their severity levels, and formatted messages for logging or user display. It extends RuntimeException to allow for unchecked exception handling in validation flows.

Key Features:

  • Carries a complete ValidationResult with all discovered issues
  • Provides formatted error messages grouped by severity
  • Supports exception chaining for root cause analysis
  • Integrates with Lombok for automatic getter generation

When This Exception Is Thrown:

  • Schema validation encounters critical errors
  • Cross-reference validation finds invalid references
  • Business rules are severely violated
  • Required resources are missing or invalid

Usage Example:


 try {
     ValidationResult result = validator.validateConfiguration(
         projectJson, dslJson, imagePath);

     if (result.hasCriticalErrors()) {
         throw new ConfigValidationException(
             "Configuration has critical errors", result);
     }
 } catch (ConfigValidationException e) {
     // Log the formatted error message
     logger.error("Validation failed: {}", e.getMessage());

     // Access detailed validation results
     ValidationResult details = e.getValidationResult();
     details.getCriticalErrors().forEach(error -> {
         alertUser(error.errorCode(), error.message());
     });
 }
 
Author:
jspinak
See Also:
  • Constructor Details

    • ConfigValidationException

      public ConfigValidationException(String message)
      Creates a new validation exception with a simple message.

      Use this constructor when you have a general validation failure message but no detailed ValidationResult. An empty ValidationResult will be created.

      Parameters:
      message - Error message describing the validation failure
    • ConfigValidationException

      public ConfigValidationException(ValidationResult validationResult)
      Creates a new validation exception from a ValidationResult.

      This constructor automatically generates a formatted error message from the validation result, grouping errors by severity. This is useful when you want the exception message to contain all validation details.

      Parameters:
      validationResult - Result containing validation errors to include in the exception. The result's errors will be formatted into a human-readable message
    • ConfigValidationException

      public ConfigValidationException(String message, ValidationResult validationResult)
      Creates a new validation exception with a custom message and detailed results.

      This constructor combines a custom message with the formatted validation errors. Use this when you want to provide context about why validation was performed along with the specific errors found.

      Parameters:
      message - High-level error message providing context
      validationResult - Detailed validation errors to append to the message
    • ConfigValidationException

      public ConfigValidationException(String message, Throwable cause)
      Creates a new validation exception with a root cause.

      Use this constructor when validation fails due to an underlying exception, such as JSON parsing errors or I/O failures. The cause will be preserved for debugging purposes.

      Parameters:
      message - Error message describing the validation failure
      cause - The exception that triggered the validation failure, such as a JSONException or IOException
    • ConfigValidationException

      public ConfigValidationException(String message, Throwable cause, ValidationResult validationResult)
      Creates a new validation exception with complete error information.

      This constructor provides the most complete error information by combining a custom message, root cause exception, and detailed validation results. Use this for comprehensive error reporting in complex validation scenarios.

      Parameters:
      message - High-level description of the validation failure
      cause - The underlying exception that triggered validation failure
      validationResult - Detailed validation errors discovered before the exception occurred
  • Method Details

    • getValidationResult

      public ValidationResult getValidationResult()
      -- GETTER -- Gets the validation result associated with this exception.
      Returns:
      Validation result