Skip to main content

ValidationError

Struct ValidationError 

Source
pub struct ValidationError {
    pub violations: Vec<Violation>,
    pub compile_error: Option<String>,
    pub runtime_error: Option<String>,
}

Fields§

§violations: Vec<Violation>§compile_error: Option<String>

Non-empty when the generated validator detected at code-gen time that a rule was malformed (mismatched rule/field type, malformed oneof spec, CEL referencing a non-existent field). Maps to protovalidate’s compilation error.

§runtime_error: Option<String>

Non-empty when a rule’s runtime precondition failed. Examples: bytes.pattern applied to non-UTF-8 input; a CEL expression that the plugin transpiler classified as always-runtime-error (e.g. dyn(this).<unknown_field>); a CEL expression the transpiler couldn’t compile (the unsupported construct is inlined into the error message). Maps to protovalidate’s runtime error.

Implementations§

Source§

impl ValidationError

Source

pub fn to_proto(&self) -> Violations

Copies all violations into the canonical buf.validate.Violations type.

Requires protos. Preserves messages, map keys, indexes, schema paths, and rule IDs without a size limit. Empty paths, rule IDs and messages are absent; for_key is present only when true. Compilation and evaluation diagnostics remain on self: the schema has no fields for them.

This diagnostic representation can contain rejected data. For public RPC request errors, use into_connect_error (requires connect), which applies redaction, size limits, and status classification.

use protovalidate_buffa::{ValidationError, proto};
let error = ValidationError::default();
let details: proto::Violations = error.to_proto();
assert!(details.violations.is_empty());
Source§

impl ValidationError

Source

pub fn into_connect_error(self) -> ConnectError

Converts an RPC request validation failure into a transport error.

Requires connect. Violations produce invalid_argument with one canonical proto::Violations detail. Compilation/evaluation failures take precedence (including mixed states), producing internal with no details. An empty error is also internal.

Public messages are fixed. Detail messages and all map keys are omitted; rule IDs, schema names/numbers/types, repeated indexes and for_key are retained. Without map selectors, paths identify schema locations but cannot identify a particular map entry. Schema names and rule IDs are assumed to be schema-authored, not populated with rejected values.

Details contain a prefix of whole violations whose combined protobuf encoding is at most 4096 bytes. If the next violation cannot fit, it and all subsequent violations are omitted, and the public message indicates truncation. No detail is attached if none fit. This leaves gRPC envelope and base64 headroom, but is not a limit on the complete metadata block. Callers adding metadata/details must budget those separately.

The original error is retained as std::error::Error::source() and is never serialized. It, and Self::to_proto, may contain rejected data. Response validation is not performed by connect_impl; callers that validate server responses should use a generic ConnectError::internal with the diagnostic as its source instead of this request conversion.

use protovalidate_buffa::ValidationError;
use connectrpc::ErrorCode;
let failure = ValidationError {
    compile_error: Some("private diagnostic".into()),
    ..Default::default()
};
let rpc_error = failure.into_connect_error();
assert_eq!(rpc_error.code, ErrorCode::Internal);
assert!(rpc_error.details.is_empty());

Trait Implementations§

Source§

impl Clone for ValidationError

Source§

fn clone(&self) -> ValidationError

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ValidationError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ValidationError

Source§

fn default() -> ValidationError

Returns the “default value” for a type. Read more
Source§

impl Display for ValidationError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for ValidationError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> JsonDeserialize for T

Source§

impl<T> JsonSerialize for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more