Skip to content

crv.core.errors

Experimental API

crv.core.errors

Core exception types raised by grammar validation, schema checks, and versioning.

Provides typed exceptions for core-domain failures: - GrammarError for grammar/naming/normalization violations. - SchemaError for schema-level constraints and cross-field combination rules. - VersionMismatch for schema version incompatibilities against SCHEMA_V.

Notes
  • This module uses only the Python standard library and has no side effects.
  • Validators in crv.core.schema raise:
    • GrammarError for naming/normalization failures.
    • SchemaError for combination/range violations.
  • Version guards raise VersionMismatch when artifacts do not match SCHEMA_V.

Examples:

Catch a normalization failure.

>>> from crv.core.errors import GrammarError
>>> def normalize_demo(s: str) -> str:
...     if any(c.isupper() for c in s):
...         raise GrammarError("value must be lower_snake")
...     return s
>>> try:
...     normalize_demo("Not_Lower_Snake")
... except GrammarError as e:
...     msg = str(e)
>>> "lower_snake" in msg
True

crv.core.errors.SchemaError

Bases: ValueError

Schema-level validation failure (shape, constraints, cross-field rules).

Source code in src/crv/core/errors.py
class SchemaError(ValueError):
    """Schema-level validation failure (shape, constraints, cross-field rules)."""

crv.core.errors.VersionMismatch

Bases: RuntimeError

Incompatible or unexpected schema version encountered.

Source code in src/crv/core/errors.py
class VersionMismatch(RuntimeError):
    """Incompatible or unexpected schema version encountered."""

crv.core.errors.GrammarError

Bases: ValueError

Grammar/naming normalization failure (e.g., not lower_snake or invalid enum value).

Source code in src/crv/core/errors.py
class GrammarError(ValueError):
    """Grammar/naming normalization failure (e.g., not lower_snake or invalid enum value)."""