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: ViolationKindWhat kind of constraint was violated.
blame_chain: Vec<BlameEntry>Ordered chain of blame entries (CON-205).
detail: StringHuman-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 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
impl ViolationError
Sourcepub fn with_recipient(self, recipient: impl Into<String>) -> Self
pub fn with_recipient(self, recipient: impl Into<String>) -> Self
Set the recipient (the party the error is addressed to).
Sourcepub fn with_verifier(self, verifier: impl Into<String>) -> Self
pub fn with_verifier(self, verifier: impl Into<String>) -> Self
Set the verifier (the agent that performed the check).
Sourcepub fn with_dialect_context(
self,
dialect_name: &str,
dialect_author: Option<&str>,
dialect_hash: Option<&str>,
performative: Option<&str>,
) -> Self
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.
Sourcepub fn with_message_hash(self, hash: impl Into<String>) -> Self
pub fn with_message_hash(self, hash: impl Into<String>) -> Self
Set the message hash.
Sourcepub fn with_thread_id(self, thread: impl Into<String>) -> Self
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).
Sourcepub fn from_shape_violation(
violation: &ShapeViolation,
message_hash: Option<String>,
thread_id: Option<String>,
evidence: Option<SExpr>,
) -> Self
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.
Sourcepub fn from_causal_violation(
violation: &CausalViolation,
message_hash: Option<String>,
thread_id: Option<String>,
) -> Self
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.
Sourcepub fn from_unsatisfiable_shape(
dialect_name: &str,
constraint_summary: &str,
rationale: &str,
) -> Self
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.
Sourcepub fn from_r5_violation(dialect_name: &str, violations: &[String]) -> Self
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).
Sourcepub fn to_sexpr(&self) -> SExpr
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).
Sourcepub fn verify_blame(&self, shape_constraint: Option<&ShapeConstraint>) -> bool
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).
Sourcepub fn record_metrics(&self, dialect: &str)
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.