Skip to content

Errors

Crease's error model is pydantic-shaped: every problem the library surfaces — whether structural (template can't map the file) or cell-level (a value violated a constraint) — is represented as the same Error type, with the same five fields.

Error dataclass

Error(
    type: str,
    loc: tuple[str | int | None, ...],
    msg: str = "",
    input: Any = None,
    ctx: dict[str, Any] = dict(),
    severity: Severity = "cell",
)

A single problem surfaced by crease.

Fields mirror pydantic.ValidationError.errors() entries, with one crease addition: severity distinguishes structural errors (the template can't map the file at all) from cell-level errors (an individual value violated a constraint).

Attributes:

Name Type Description
type str

Stable machine code for routing — e.g. "wrong_type", "missing_required", "pattern_mismatch". See the README for the full taxonomy.

loc tuple[str | int | None, ...]

(entity, row, field) tuple identifying where the problem was found. Any element may be None for errors that don't apply to a specific row or field (e.g. missing_tab).

msg str

Human-readable description.

input Any

The offending value, if applicable. None for structural errors with no specific cell.

ctx dict[str, Any]

Extra context — for example {"likely_cause": "excel_autoconvert"} when a string field received what looks like an Excel-autoconverted date.

severity Severity

"cell" or "structural". Derived from type.

type instance-attribute

type: str

loc instance-attribute

loc: tuple[str | int | None, ...]

msg class-attribute instance-attribute

msg: str = ''

input class-attribute instance-attribute

input: Any = None

ctx class-attribute instance-attribute

ctx: dict[str, Any] = field(default_factory=dict)

severity class-attribute instance-attribute

severity: Severity = 'cell'

is_structural property

is_structural: bool

is_cell property

is_cell: bool

to_dict

to_dict() -> dict[str, Any]

Serialize to a plain dict suitable for JSON output.

ValidationError

ValidationError(
    errors: list[Error], message: str | None = None
)

Bases: Exception

Raised by halt-by-default projection methods when crease has errors to report.

The exception carries the full Error list — same shape as Report.errors() would have produced. Pattern after Pydantic's ValidationError:

try:
    orders = result.to_pydantic("order", model=Order)
except crease.ValidationError as e:
    for err in e.errors():
        print(err.type, err.loc, err.msg)

errors

errors() -> list[Error]

Return the full list of errors. Same shape as Report.errors().

error_count

error_count() -> int

Error type taxonomy

The error.type field is a stable machine code safe to route on. The full taxonomy is in the README's error table.