angzarr_client.validation¶
Validation helpers for command handler precondition checks.
Eliminates repeated validation boilerplate across aggregate handlers.
Audit finding #59 (structural error model). Errors carry a SCREAMING_SNAKE
code (from angzarr_client.error_codes.codes), a static
message (from angzarr_client.error_codes.messages), and
structured details (keyed by angzarr_client.error_codes.keys).
The structured info-level log emitted alongside surfaces the same
fields for observability.
Functions¶
|
Require that an aggregate exists (caller-supplied predicate). |
|
Require that an aggregate does NOT exist (caller-supplied predicate). |
|
Require that a value is greater than zero. |
|
Require that a value is zero or greater. |
|
Require that a sequence has at least one element. |
|
Require that a string is not empty. |
|
Require that the current status matches the expected value. |
|
Require that the current status is NOT the forbidden value. |
Module Contents¶
- angzarr_client.validation.require_exists(exists: bool, context: str) None¶
Require that an aggregate exists (caller-supplied predicate).
Audit #60: takes a precomputed predicate boolean (e.g.
state.is_some()/bool(state.id)) so the callsite is explicit about what “exists” means. Mirrors Rust’svalidation.rs:41require_exists(exists: bool, context: &str).Raises NOT_FOUND — not retryable, since refetching events cannot change the outcome. For empty-string checks, use
require_not_empty_str().
- angzarr_client.validation.require_not_exists(exists: bool, context: str) None¶
Require that an aggregate does NOT exist (caller-supplied predicate).
Audit #60: takes a precomputed predicate boolean. Mirrors Rust’s
validation.rs:54require_not_exists(exists: bool, context: &str).
- angzarr_client.validation.require_positive(value: _Numeric, field_name: str) None¶
Require that a value is greater than zero.
- angzarr_client.validation.require_non_negative(value: _Numeric, field_name: str) None¶
Require that a value is zero or greater.
- angzarr_client.validation.require_not_empty(items: collections.abc.Sequence[Any], field_name: str) None¶
Require that a sequence has at least one element.
- angzarr_client.validation.require_not_empty_str(value: str, field_name: str) None¶
Require that a string is not empty.