pub fn decode_violations(
detail: &ErrorDetail,
) -> Result<Option<Violations>, DecodeViolationsError>Expand description
Decodes a canonical validation detail from a Connect or gRPC error.
Requires connect. Accepts the bare protobuf name or a type URL whose last
segment is buf.validate.Violations, including type.googleapis.com/.
Returns Ok(None) for unrelated types; never uses the optional JSON debug
value. Padded and unpadded standard base64 are accepted.
Receiver limits are 4096 decoded bytes, 5464 base64 bytes (checked before allocation), and 1 MiB of repeated/map element memory through buffa’s decode options. Its default recursion and unknown-field limits also apply. Unknown protobuf fields are accepted. Peer messages and map keys are preserved; decoding does not impose this library’s sender redaction policy.
§Errors
Returns DecodeViolationsError for a matching detail with a missing value,
invalid base64/protobuf, exceeded limits, or no violations. A decoded detail
describes failures; it does not establish the enclosing RPC status. Callers
should inspect ConnectError::code as well.
use protovalidate_buffa::{decode_violations, proto};
let message = proto::Violations {
violations: vec![proto::Violation {
rule_id: Some("string.min_len".into()),
..Default::default()
}],
..Default::default()
};
let detail = connectrpc::ErrorDetail::from_message("buf.validate.Violations", &message);
let decoded = decode_violations(&detail)?.unwrap();
assert_eq!(decoded.violations[0].rule_id.as_deref(), Some("string.min_len"));