Errors#

class AnzaError(code: Literal['VALIDATION', 'NOT_FOUND', 'TEMPLATE', 'CRYPTO', 'INTERNAL'], message: str)[source]#

An engine error with a stable code.

str(error) is "[Anza:<code>] <message>".

Code

Raised for

VALIDATION

Bad input: an empty route, template or slot, a malformed template name, a template root that does not exist.

NOT_FOUND

An unknown page route or template, a fragment outside the fragments allowlist, a template that resolves outside the root or cannot be read.

TEMPLATE

A template that is not UTF-8, is larger than max_template_bytes or has an unclosed/empty placeholder.

CRYPTO

A missing, short or mismatched signing key, and every failed envelope check in verify_envelope().

INTERNAL

An unexpected engine failure.

Parameters:
  • code – One of the codes above.

  • message – What went wrong.

code#

The error code.

message#

The message, without the [Anza:<code>] prefix.

Example

>>> from anza import AnzaError
>>> err = AnzaError.not_found("Page not found")
>>> err.code, err.message
('NOT_FOUND', 'Page not found')
>>> str(err)
'[Anza:NOT_FOUND] Page not found'
classmethod validation(msg: str) → AnzaError[source]#

Build a VALIDATION error.

classmethod not_found(msg: str) → AnzaError[source]#

Build a NOT_FOUND error.

classmethod template(msg: str) → AnzaError[source]#

Build a TEMPLATE error.

classmethod crypto(msg: str) → AnzaError[source]#

Build a CRYPTO error.

classmethod internal(msg: str) → AnzaError[source]#

Build an INTERNAL error.