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_exists(→ None)

Require that an aggregate exists (caller-supplied predicate).

require_not_exists(→ None)

Require that an aggregate does NOT exist (caller-supplied predicate).

require_positive(→ None)

Require that a value is greater than zero.

require_non_negative(→ None)

Require that a value is zero or greater.

require_not_empty(→ None)

Require that a sequence has at least one element.

require_not_empty_str(→ None)

Require that a string is not empty.

require_status(→ None)

Require that the current status matches the expected value.

require_status_not(→ None)

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’s validation.rs:41 require_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:54 require_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.

angzarr_client.validation.require_status(actual: str, expected: str, context: str) None

Require that the current status matches the expected value.

angzarr_client.validation.require_status_not(actual: str, forbidden: str, context: str) None

Require that the current status is NOT the forbidden value.