Home / Class/ ValidationException Class — fastapi Architecture

ValidationException Class — fastapi Architecture

Architecture documentation for the ValidationException class in exceptions.py from the fastapi codebase.

Entity Profile

Dependency Diagram

graph TD
  32a73308_3432_5041_09d0_0ac7de6c0780["ValidationException"]
  01c652c5_d85c_f45e_848e_412c94ea4172["exceptions.py"]
  32a73308_3432_5041_09d0_0ac7de6c0780 -->|defined in| 01c652c5_d85c_f45e_848e_412c94ea4172
  ec1c325b_ff97_c562_9aaa_f51dbaba666e["__init__()"]
  32a73308_3432_5041_09d0_0ac7de6c0780 -->|method| ec1c325b_ff97_c562_9aaa_f51dbaba666e
  7702da8c_3f6b_a8bb_d4ca_61939c372354["errors()"]
  32a73308_3432_5041_09d0_0ac7de6c0780 -->|method| 7702da8c_3f6b_a8bb_d4ca_61939c372354
  b450d08c_60f4_509a_84c3_0b5d46e7942a["_format_endpoint_context()"]
  32a73308_3432_5041_09d0_0ac7de6c0780 -->|method| b450d08c_60f4_509a_84c3_0b5d46e7942a
  5b458d6f_ef49_5bcd_d6b6_bbc9909a7a58["__str__()"]
  32a73308_3432_5041_09d0_0ac7de6c0780 -->|method| 5b458d6f_ef49_5bcd_d6b6_bbc9909a7a58

Relationship Graph

Source Code

fastapi/exceptions.py lines 174–209

class ValidationException(Exception):
    def __init__(
        self,
        errors: Sequence[Any],
        *,
        endpoint_ctx: Optional[EndpointContext] = None,
    ) -> None:
        self._errors = errors
        self.endpoint_ctx = endpoint_ctx

        ctx = endpoint_ctx or {}
        self.endpoint_function = ctx.get("function")
        self.endpoint_path = ctx.get("path")
        self.endpoint_file = ctx.get("file")
        self.endpoint_line = ctx.get("line")

    def errors(self) -> Sequence[Any]:
        return self._errors

    def _format_endpoint_context(self) -> str:
        if not (self.endpoint_file and self.endpoint_line and self.endpoint_function):
            if self.endpoint_path:
                return f"\n  Endpoint: {self.endpoint_path}"
            return ""

        context = f'\n  File "{self.endpoint_file}", line {self.endpoint_line}, in {self.endpoint_function}'
        if self.endpoint_path:
            context += f"\n    {self.endpoint_path}"
        return context

    def __str__(self) -> str:
        message = f"{len(self._errors)} validation error{'s' if len(self._errors) != 1 else ''}:\n"
        for err in self._errors:
            message += f"  {err}\n"
        message += self._format_endpoint_context()
        return message.rstrip()

Domain

Frequently Asked Questions

What is the ValidationException class?
ValidationException is a class in the fastapi codebase, defined in fastapi/exceptions.py.
Where is ValidationException defined?
ValidationException is defined in fastapi/exceptions.py at line 174.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free