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
impl ValidationError
Sourcepub fn to_proto(&self) -> Violations
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
impl ValidationError
Sourcepub fn into_connect_error(self) -> ConnectError
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
impl Clone for ValidationError
Source§fn clone(&self) -> ValidationError
fn clone(&self) -> ValidationError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ValidationError
impl Debug for ValidationError
Source§impl Default for ValidationError
impl Default for ValidationError
Source§fn default() -> ValidationError
fn default() -> ValidationError
Source§impl Display for ValidationError
impl Display for ValidationError
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()