pub struct ValidationError<'a> { /* private fields */ }Expand description
An error that can occur during validation.
Implementations§
Source§impl<'a> ValidationError<'a>
Shortcuts for creation of specific error kinds.
impl<'a> ValidationError<'a>
Shortcuts for creation of specific error kinds.
Sourcepub fn instance(&self) -> &Cow<'a, Value>
pub fn instance(&self) -> &Cow<'a, Value>
Returns a reference to the instance that failed validation.
Sourcepub fn kind(&self) -> &ValidationErrorKind
pub fn kind(&self) -> &ValidationErrorKind
Returns the kind of validation error.
Sourcepub fn instance_path(&self) -> &Location
pub fn instance_path(&self) -> &Location
Returns the JSON Pointer to the instance location that failed validation.
Sourcepub fn schema_path(&self) -> &Location
pub fn schema_path(&self) -> &Location
Returns the canonical schema location without $ref traversals.
This corresponds to JSON Schema’s “keywordLocation” in output formats. See JSON Schema 2020-12 Core, Section 12.4.2.
Sourcepub fn evaluation_path(&self) -> &Location
pub fn evaluation_path(&self) -> &Location
Returns the dynamic evaluation path including $ref traversals.
This corresponds to JSON Schema’s “evaluationPath” - the actual path taken
through the schema including by-reference applicators ($ref, $dynamicRef).
See JSON Schema 2020-12 Core, Section 12.4.2.
Sourcepub fn absolute_keyword_location(&self) -> Option<&Uri<String>>
pub fn absolute_keyword_location(&self) -> Option<&Uri<String>>
Returns the absolute keyword location as a full URI including JSON Pointer fragment.
This corresponds to JSON Schema’s “absoluteKeywordLocation” (e.g.
https://example.com/schema.json#/properties/name/type).
Present when the schema has a real base URI set via $id or crate::options::ValidationOptions::with_base_uri.
None for schemas without an explicit base URI.
Sourcepub fn into_parts(self) -> ValidationErrorParts<'a>
pub fn into_parts(self) -> ValidationErrorParts<'a>
Decomposes the error into its owned parts.
Sourcepub fn masked<'b>(&'b self) -> MaskedValidationError<'a, 'b, 'static>
pub fn masked<'b>(&'b self) -> MaskedValidationError<'a, 'b, 'static>
Returns a wrapper that masks instance values in error messages. Uses “value” as a default placeholder.
Sourcepub fn masked_with<'b, 'c>(
&'b self,
placeholder: impl Into<Cow<'c, str>>,
) -> MaskedValidationError<'a, 'b, 'c>
pub fn masked_with<'b, 'c>( &'b self, placeholder: impl Into<Cow<'c, str>>, ) -> MaskedValidationError<'a, 'b, 'c>
Returns a wrapper that masks instance values in error messages with a custom placeholder.
Sourcepub fn to_owned(self) -> ValidationError<'static>
pub fn to_owned(self) -> ValidationError<'static>
Converts the ValidationError into an owned version with 'static lifetime.
Sourcepub fn custom(message: impl Into<String>) -> ValidationError<'static>
pub fn custom(message: impl Into<String>) -> ValidationError<'static>
Create a custom validation error with just a message.
Use this in Keyword::validate implementations.
The actual instance, instance path, and schema path are filled in automatically.
§Example
use jsonschema::ValidationError;
fn validate_even(n: u64) -> Result<(), ValidationError<'static>> {
if n % 2 != 0 {
return Err(ValidationError::custom("number must be even"));
}
Ok(())
}Sourcepub fn schema(message: impl Into<String>) -> ValidationError<'static>
pub fn schema(message: impl Into<String>) -> ValidationError<'static>
Create an error for invalid schema values in keyword factories.
Use this in custom keyword factory functions when the schema value is invalid for your custom keyword.
Trait Implementations§
Source§impl<'a> Debug for ValidationError<'a>
impl<'a> Debug for ValidationError<'a>
Source§impl Display for ValidationError<'_>
Textual representation of various validation errors.
impl Display for ValidationError<'_>
Textual representation of various validation errors.
Source§impl Error for ValidationError<'_>
impl Error for ValidationError<'_>
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()