Skip to main content

ViolationError

Struct ViolationError 

Source
pub struct ViolationError {
Show 16 fields pub kind: ViolationKind, pub blame_chain: Vec<BlameEntry>, pub detail: String, pub recipient: Option<String>, pub dialect: Option<String>, pub dialect_author: Option<String>, pub dialect_hash: Option<String>, pub performative: Option<String>, pub verifier: Option<String>, pub message_hash: Option<String>, pub caused_by: Option<String>, pub rule: Option<String>, pub field: Option<String>, pub expected: Option<String>, pub found: Option<String>, pub thread_id: Option<String>,
}
Expand description

A complete violation error with blame attribution.

Carries the violation kind, a human-readable detail, optional context (message hash, thread), and a chain of blame entries that allow third-party verification.

Fields§

§kind: ViolationKind

What kind of constraint was violated.

§blame_chain: Vec<BlameEntry>

Ordered chain of blame entries (CON-205).

§detail: String

Human-readable description of the violation.

§recipient: Option<String>

The party the error is addressed to (e.g. @sender). Positional in the ABNF; None emits @unknown as a placeholder.

§dialect: Option<String>

Dialect name.

§dialect_author: Option<String>

Dialect author identity (e.g. Ed25519 key ref).

§dialect_hash: Option<String>

Hash of the dialect definition.

§performative: Option<String>

Performative under which the violation occurred.

§verifier: Option<String>

Identity of the agent that performed the check.

§message_hash: Option<String>

Hash of the offending message.

§caused_by: Option<String>

Predecessor hash (for causal violations).

§rule: Option<String>

Shape rule text (for shape violations).

§field: Option<String>

Field/keyword that failed (for shape violations).

§expected: Option<String>

Expected type (for shape violations).

§found: Option<String>

Found type (for shape violations).

§thread_id: Option<String>

Thread in which the violation occurred. Retained for internal use (metrics, callers that want to correlate with their own thread state) but not emitted by to_sexpr — :thread is not in the REQ-233 ABNF.

Implementations§

Source§

impl ViolationError

Source

pub fn with_recipient(self, recipient: impl Into<String>) -> Self

Set the recipient (the party the error is addressed to).

Source

pub fn with_verifier(self, verifier: impl Into<String>) -> Self

Set the verifier (the agent that performed the check).

Source

pub fn with_dialect_context( self, dialect_name: &str, dialect_author: Option<&str>, dialect_hash: Option<&str>, performative: Option<&str>, ) -> Self

Populate dialect-related fields (:dialect, :dialect-author, :dialect-hash) from a Dialect. Also stamps :performative if given.

Source

pub fn with_message_hash(self, hash: impl Into<String>) -> Self

Set the message hash.

Source

pub fn with_thread_id(self, thread: impl Into<String>) -> Self

Set the thread id (kept for internal use; not emitted in the wire form).

Source

pub fn from_shape_violation( violation: &ShapeViolation, message_hash: Option<String>, thread_id: Option<String>, evidence: Option<SExpr>, ) -> Self

Create a ViolationError from a ShapeViolation (REQ-230).

Shape violations blame the Sender (who sent a message that does not conform to the declared shape) with the violating S-expression as evidence. Populates :rule, :field, :expected, :found from the violation.

Source

pub fn from_causal_violation( violation: &CausalViolation, message_hash: Option<String>, thread_id: Option<String>, ) -> Self

Create a ViolationError from a CausalViolation (REQ-230).

Causal violations blame the Sender (who sent a message with invalid causal predecessors). Populates :caused-by from the violation when the variant carries a predecessor hash.

Source

pub fn from_unsatisfiable_shape( dialect_name: &str, constraint_summary: &str, rationale: &str, ) -> Self

Create a ViolationError for an unsatisfiable shape constraint (REQ-230).

Per the SPEC-002 blame table, a shape that no valid message can satisfy is the dialect author’s fault, not the sender’s. This constructor exists for callers that detect unsatisfiability (e.g. at install time via witness/example-based R5 checks, or at first runtime failure when no sender could plausibly conform). It does not run a detector itself — callers must determine unsatisfiability and supply the rationale.

Source

pub fn from_r5_violation(dialect_name: &str, violations: &[String]) -> Self

Create a ViolationError from R5 well-formedness violations (REQ-230).

R5 violations blame the DialectAuthor (who wrote a dialect with malformed shapes or protocol) with an additional Installer entry (who installed it without catching the problem).

Source

pub fn to_sexpr(&self) -> SExpr

Serialise as a CBCL error S-expression (REQ-233).

Emits the SPEC-002 ABNF form:

(error <recipient> "shape-violation"
       :dialect <name> :dialect-author <key> :dialect-hash <hash>
       :performative <perf> :rule <rule>
       :field <field> :expected <type> :found <type>
       :detail <text>
       :blamed sender :verifier <key>
       :message-hash <hash> :caused-by <hash>
       :blame-chain (...))

Recipient is positional and falls back to @unknown if unset. Optional fields are omitted when their value is None. :thread is not emitted: it isn’t in the ABNF (thread_id is retained on the struct for internal use).

Source

pub fn verify_blame(&self, shape_constraint: Option<&ShapeConstraint>) -> bool

Verify that a shape-blame claim is justified by re-checking the evidence against the given shape constraint.

Returns true if the blame chain is verified: the evidence S-expression actually fails the shape constraint, confirming the violation is real. Returns false if the evidence passes (blame is unjustified) or if verification is not applicable (wrong kind, no evidence, no constraint).

Source

pub fn record_metrics(&self, dialect: &str)

Emit tracing events for blame attribution metrics.

Emits two events when the tracing feature is enabled:

  • cbcl_blame_attribution_count — one event per blame-chain entry, with labels {dialect, blamed_party, violation_type}.
  • cbcl_violation_error_size_bytes — the serialised S-expression byte length of this error.

This is a no-op when the tracing feature is disabled.

Trait Implementations§

Source§

impl Clone for ViolationError

Source§

fn clone(&self) -> Self

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 ViolationError

Source§

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

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

impl Display for ViolationError

Source§

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

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

impl Eq for ViolationError

Source§

impl PartialEq for ViolationError

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ViolationError

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
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.