Class ConfigValidationException
- All Implemented Interfaces:
Serializable
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 Summary
ConstructorsConstructorDescriptionConfigValidationException
(ValidationResult validationResult) Creates a new validation exception from a ValidationResult.ConfigValidationException
(String message) Creates a new validation exception with a simple message.ConfigValidationException
(String message, ValidationResult validationResult) Creates a new validation exception with a custom message and detailed results.ConfigValidationException
(String message, Throwable cause) Creates a new validation exception with a root cause.ConfigValidationException
(String message, Throwable cause, ValidationResult validationResult) Creates a new validation exception with complete error information. -
Method Summary
Modifier and TypeMethodDescription-- GETTER -- Gets the validation result associated with this exception.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
ConfigValidationException
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
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
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 contextvalidationResult
- Detailed validation errors to append to the message
-
ConfigValidationException
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 failurecause
- 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 failurecause
- The underlying exception that triggered validation failurevalidationResult
- Detailed validation errors discovered before the exception occurred
-
-
Method Details
-
getValidationResult
-- GETTER -- Gets the validation result associated with this exception.- Returns:
- Validation result
-