ValidationError
Represents a validation error found in a policy structure.
Validation errors provide detailed information about structural issues in policies, helping developers identify and fix problems quickly. Each error includes a path to the problematic field and a clear message.
Examples
// Example validation errors
const errors: ValidationError[] = [
{
path: 'policyURI',
message: 'policyURI must be a non-empty string.'
},
{
path: 'rules[0].effect',
message: 'Rule effect must be \'permit\' or \'prohibit\'.'
},
{
path: 'rules[1].constraints[2]',
message: 'Constraint must have a type field.'
}
];
// Using validation errors in practice
const result = validatePolicy(myPolicy);
if (!result.valid) {
console.error('Policy validation failed:');
result.errors.forEach(error => {
console.error(` ${error.path}: ${error.message}`);
});
}
Definition
interface ValidationError {
/**
* The path to the field that caused the error. Uses dot notation and array indices to precisely locate the issue. Empty string indicates a top-level error.
*/
path: string;
/**
* A human-readable error message. Describes what validation rule was violated and what the expected value or format should be. Messages are designed to be helpful for developers debugging policy issues.
*/
message: string;
}
Properties
path
The path to the field that caused the error.
Uses dot notation and array indices to precisely locate the issue. Empty string indicates a top-level error.
Type: string
Examples
path: '' // Root-level error
path: 'policyURI' // Top-level field
path: 'rules' // Rules array itself
path: 'rules[0]' // First rule
path: 'rules[0].effect' // Effect field of first rule
path: 'rules[2].constraints[1].type' // Nested constraint field
message
A human-readable error message.
Describes what validation rule was violated and what the expected value or format should be. Messages are designed to be helpful for developers debugging policy issues.
Type: string
Examples
message: 'policyURI must be a non-empty string.'
message: 'Rule effect must be \'permit\' or \'prohibit\'.'
message: 'Constraint type must be a string.'
message: 'Policy must have at least one rule.'
See Also
-
- validatePolicy for the validation function
- Policy for the structure being validated
Since
Version 1.0.0