Skip to content

JsonLoadError

Base classes

Name Children Inherits
Exception
builtins
Common base class for all non-exit exceptions.

⋔ Inheritance diagram

graph TD
  3308422246["base.JsonLoadError"]
  1615621424["builtins.Exception"]
  3224121899["builtins.BaseException"]
  2751680898["builtins.object"]
  1615621424 --> 3308422246
  3224121899 --> 1615621424
  2751680898 --> 3224121899

🛈 DocStrings

Bases: Exception

Unified exception for all JSON parsing errors.

Source code in src/configz/json_tools/base.py
class JsonLoadError(Exception):
    """Unified exception for all JSON parsing errors."""

    def __init__(
        self,
        message: str,
        *,
        line: int | None = None,
        column: int | None = None,
        source_path: str | Path | None = None,
        source_content: str | None = None,
    ) -> None:
        super().__init__(message)
        self.info = ParseErrorInfo(
            message=message,
            format_name="JSON Parse",
            line=line,
            column=column,
            source_path=source_path,
            source_content=source_content,
        )

    @property
    def line(self) -> int | None:
        """Line number where the error occurred."""
        return self.info.line

    @property
    def column(self) -> int | None:
        """Column number where the error occurred."""
        return self.info.column

    @property
    def source_path(self) -> str | Path | None:
        """Path to the source file that caused the error."""
        return self.info.source_path

    @property
    def source_content(self) -> str | None:
        """Source content that caused the error."""
        return self.info.source_content

    def format(self, context_lines: int = 2, use_color: bool = True) -> str:
        """Format error with source context for display.

        Args:
            context_lines: Number of lines to show before/after the error line.
            use_color: Whether to include ANSI color codes.
        """
        return self.info.format(context_lines=context_lines, use_color=use_color)

column property

column: int | None

Column number where the error occurred.

line property

line: int | None

Line number where the error occurred.

source_content property

source_content: str | None

Source content that caused the error.

source_path property

source_path: str | Path | None

Path to the source file that caused the error.

format

format(context_lines: int = 2, use_color: bool = True) -> str

Format error with source context for display.

Parameters:

Name Type Description Default
context_lines int

Number of lines to show before/after the error line.

2
use_color bool

Whether to include ANSI color codes.

True
Source code in src/configz/json_tools/base.py
def format(self, context_lines: int = 2, use_color: bool = True) -> str:
    """Format error with source context for display.

    Args:
        context_lines: Number of lines to show before/after the error line.
        use_color: Whether to include ANSI color codes.
    """
    return self.info.format(context_lines=context_lines, use_color=use_color)

:fa-brands-github: Show source on GitHub